Ordering a list of GameObjects

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class GoList : MonoBehaviour {
	public GameObject[] enemyList;
	public int enemyListLength;

	// Use this for initialization
	void Awake () {
		enemyList = GameObject.FindGameObjectsWithTag ("Enemy");
		enemyListLength = enemyList.Length;


		List<GameObject> GObj = new List<GameObject> ();

		for (int i = 0; i < enemyListLength; i++){
			GObj.Add (enemyList*);*

_ print (enemyList*.name);_
_
}*_

* GObj.Sort ();*
* }*

* // Update is called once per frame*
* void Update () {*

* }*
}
When I run this code I get an error (ArgumentException: does not implement right interface) on the line with sort. If I comment that line everything works great, except for the fact that the list isn’t sorted. I want to be able to sort the list based off a variable stored in the GameObjects. Some research I’ve done says the icomparer/icomparable might help, but I have no idea how to implement that. I’d prefer no to use Linq if I can get away with it, it still confuses the heck out of me haha. Any and all help will be appreciated!

Essentially the error is telling you there is no natural way to sort a list of GameObjects. How do you tell if which GameObject comes first?

You need to provide a sort method to GObj.Sort(). The following pseudo code sorts the GameObjects in alphabetical order by name.

....
GObj.Sort(SortMethod(GameObject A, GameObjectB));
....

private int SortMethod  (GameObject A, GameObjectB){
    if (!A && !B) return 0;
    else if (!A) return -1;
    else if (!B) return 1;
    else return A.name.CompareTo(B.name);
}

May I direct you to this question I asked myself some time ago, it has everything you need (albeit in UnityScript):

I think you can write an inherited class from IComparer to tell the code how to sort your list. I believe this code works - haven’t gotten to multiplayer testing yet so it might need some tweaking.

using System.Collections.Generic;

public class AggroComparer : IComparer<AggroData>
{
    public int Compare(AggroData x, AggroData y)
    {
        if (x.AggroLevel == y.AggroLevel)
        {
            return 0;
        }
        if (y.AggroLevel > x.AggroLevel)
        {
            return 1;
        }
        else return -1;
    }
}