Multilevel Sorting with IComparable and IComparer: Listing 2.

Calling List.Sort using the default ordering.

List<City> list = new List<City>();

list.Add(new City("san diego", 1.2, "west"));
list.Add(new City("phoenix", 1.7, "west"));
list.Add(new City("chicago", 1.2, "north"));
list.Add(new City("boston", 1.0, "east"));
list.Add(new City("nashville", 1.2, "south"));
list.Add(new City("houston", 1.7, "west"));

foreach (City c in list) {


foreach (City c in list) {

About the Author

Dr. James McCaffrey works for Microsoft Research in Redmond, Wash. He has worked on several Microsoft products including Azure and Bing. James can be reached at

comments powered by Disqus


.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events