Skip to content

Instantly share code, notes, and snippets.

@pipiscrew
Created August 16, 2015 15:15
Show Gist options
  • Save pipiscrew/77df9a2b0fb005ba1271 to your computer and use it in GitHub Desktop.
Save pipiscrew/77df9a2b0fb005ba1271 to your computer and use it in GitHub Desktop.
Class Sort
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