/ Published in: C#
One of those things in C# for which I always forget the syntax.
Expand |
Embed | Plain Text
//declare a class person class Person { public string Name; public Person(string name) { this.Name = name; } } //create a list //Writes out "Bernhard, Adam" foreach (Person p in persons) { Console.Write(p.Name+", "); } //Sort the list by name ascending persons.Sort(delegate(Person a, Person b) { return a.Name.CompareTo(b.Name); }); //The sorted list now writes out "Adam, Bernhard" foreach (Person p in persons) { Console.Write(p.Name+", "); }
Comments
Subscribe to comments
You need to login to post a comment.

Wait, how does this work?
Sorry Vordreller. I updated the snippet to hopefully make it more clear.