[Solved] Sort list numericallyC# [closed]


You can in-place sort scores if you want, using List.Sort(Comparison<T>):

scores.Sort((a, b) => int.Parse(a.Punten).CompareTo(int.Parse(b.Punten)));

Note that because Punten appears to be a string, you need to convert it to an int to compare properly.

If you change your code to make Punten an int, the sorting code would simplify to:

scores.Sort((a, b) => a.Punten.CompareTo(b.Punten));

What’s happening here is that we are supplying a comparison function with which the sort will compare pairs of items to determine the required order.

(a, b) in the code above specifies two parameters of the element type of the list to compare. We just need to compare their Punten properties.

solved Sort list numericallyC# [closed]