Welcome to AspAdvice Sign in | Join | Help

Sort Generic List of T

Plenty of others have written about this so I'll keep it brief.  I needed to sort some objects based on a string property.  Some quick searching led me to this post which got me close to what I wanted.

 

My final code was this:

myThings.Sort(delegate(Thing x, Thing y) { return String.Compare(x.Name,y.Name); }); 

myThings is a List<Thing> collection.  String.Compare done in this fashion will sort them alphabetically - reverse its parameters to sort in reverse.

Published Sunday, June 17, 2007 1:12 AM by ssmith
Filed under:

Comments

New Comments to this post are disabled