- Home /
Linq OrderBy GameObject's name Numerical
For example:
My Unsorted list
13,543
1,034
2,652
My Sorted list
1,034
13,543
2,652
Trying to achieve:
1,034
2,652
13,543
Currently using this line of code:
highScores = highScores.OrderBy (go => go.name).ToList ();
Comment
delete ".name" : highScores.OrderBy (go => go).ToList ();
assu$$anonymous$$g highscores are just a list or array of float. If it is a class or dictionary then go.value or something like that.
It is an array of GameObjects which has a float as name
Best Answer
Answer by bobisgod234 · Apr 12, 2017 at 12:02 AM
That would mean your highscore value is being stored as a string, and LINQ is trying to sort alphabetically. Try:
highScores = highScores.OrderBy (go => float.Parse(go.name)).ToList ();