Sorting an array of GameObjects by their position

I have an array of GameObjects and I need to sort them by their position. My array is

IEnumerable platforms = GameObject.FindGameObjectsWithTag("Platform").AsEnumerable()  

I have tried using

platforms = platforms.OrderBy(platform => platform.transform.position);

to sort it, but it has the error

error CS0411: The type arguments for method `System.Linq.Enumerable.OrderBy<TSource,TKey>(this   

`` System.Collections.Generic.IEnumerable, System.Func)’ cannot be inferred from the usage. Try specifying the type arguments explicitly.

Is there a better way to do this?

You can only sort lists by a single value, whereas a position vector contains 3 values (x, y, z). You need to be more specific about what exactly you want to sort by, as just sorting by position doesn’t make any sense, to either the computer or a human.

You could sort by position on the x-axis:

platforms = platforms.OrderBy(platform => platform.transform.position.x);

or you could sort by distance from the origin:

platforms = platforms.OrderBy(platform => platform.transform.position.sqrMagnitude);

or you could do something fancier like sorting by location on an x-z grid:

private float GridRanking(Vector3 Pos)
    return pos.x + 100 * pos.z;

platforms = platforms.OrderBy(platform => GridRanking(platform.transform.position));

The above code is an example only, and should sort items into cells of 1x1 unit on the horizontal plane, so long as no item has an x-coord above 100 (increase the multiplier if it has). It also won’t work for negative coordinates.

If you provide more details about what it is your trying to achieve, I can try and produce some better code.