Skip to content

Instantly share code, notes, and snippets.

@snippe
Created January 24, 2015 07:01
Show Gist options
  • Save snippe/3a08dd3b968651167e75 to your computer and use it in GitHub Desktop.
Save snippe/3a08dd3b968651167e75 to your computer and use it in GitHub Desktop.
Sorting a list
public class Program
{
static void Main(string[] args)
{
Person p1 = new Person() { Name = "Person 1", Age = 34 };
Person p2 = new Person() { Name = "Person 2", Age = 31 };
Person p3 = new Person() { Name = "Person 3", Age = 33 };
Person p4 = new Person() { Name = "Person 4", Age = 26 };
List<Person> people = new List<Person> { p1, p2, p3, p4 };
//Exception : Failed to compare two elements in the array
people.Sort();
}
}
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment