(C#) Sort lists


Lets say you have a list of person objects (List persons)

You may use Sort to update the existing list.
[c language=”#”]
personsList.Sort((x, y) => string.Compare(x.Name, y.Name));
[/c]
or OrderBy to produce a new, ordered list.
[c language=”#”]
var newPersonsList = persons.OrderBy(x => x.Name);
[/c]

Leave a Reply

Your email address will not be published. Required fields are marked *