Created
August 16, 2015 15:15
-
-
Save pipiscrew/77df9a2b0fb005ba1271 to your computer and use it in GitHub Desktop.
Class Sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person { | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
} | |
// IN FORM - Create a list of people | |
List<Person> people = new List<Person>(); | |
people.Add(new Person() { FirstName = "Gottfried", LastName = "Leibniz" }); | |
people.Add(new Person() { FirstName = "Marie", LastName = "Curry" }); | |
people.Add(new Person() { FirstName = "Albert", LastName = "Einsten" }); | |
people.Add(new Person() { FirstName = "Isaac", LastName = "Newton" }); | |
people.Add(new Person() { FirstName = "Niels", LastName = "Bohr" }); | |
people.Sort( | |
delegate(Person x, Person y) { | |
if (x == null) { | |
if (y == null) { return 0; } | |
return -1; | |
} | |
if (y == null) { return 0; } | |
return x.FirstName.CompareTo(y.FirstName); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment