I have a List of objects in C#. All the objects contain properties code1 and code2 (among other properties). The list of objects is in no particular order. I need to sort the li
You could use linq extensions (leaving the original list unsorted):
var sorted = theList.OrderBy(o => o.code1).ThenBy(o => o.code2);
To replace the original list with a sorted one, make a slight amendment (not very efficient, it creates a new list):
theList = theList.OrderBy(o => o.code1).ThenBy(o => o.code2).ToList();
This assumes that your list is of the correct type, something like:
List theList = new List();
And not a list of objects, in which case you would need to make use of .Cast<>()
or .OfType<>()
.