does not implement right interface

I don’t know how to solve this kind of issue.
I have 5 gameobjects that listed in my List(). the issue was when i tried to sort the list there’s an error “ArgumentException: does not implement right interface”.
The listOfGameobject already contains 5 slots for 5 gameobject in editor and already filled.

I’ll show my codes:

public List<Transform> listOfGameobject;
private bool toggleMenu = false;

void Update()
{
    if (Input.GetKeyUp(KeyCode.M))
    {
        toggleMenu = !toggleMenu;
    }
}

void OnGUI()
{        
    if (toggleMenu)
    {
        for (int i = 0; i < listOfGameobject.Count; i++)
        {
            if (GUI.Button(new Rect(Screen.width - 300, (xLocation + 25) * i, 300, 25), listOfGameobject*.name))*

{
Debug.Log(listOfGameobject*.name);*
}
}
}
if (GUILayout.Button(“Sort”))
{
listOfGameobject.Sort();
}
}

Things that are sorted need to implement the IComparable interface or you need to create an class that implements IComparer on a class and pass an instance of that to sort.

The problem is - what are you sorting these things on? Transform doesn’t implement IComparable because there is no obvious order for transforms. Your easiest way might be to use Linq:

   using Linq;

   ...

   listOfGameObject = listOfGameObject.OrderBy(t=>t.position.z /* Or whatever */).ToList();