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(<span class="kwrd">delegate</span>(Thing x, Thing y) { <span class="kwrd">return</span> String.Compare(x.Name,y.Name); });

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

If you liked this post, consider subscribing to email updates about my new posts, or sharing it on Hacker News.

Keyboard shortcuts

?
Show this help
Esc
Close this help or an open menu
n
Next (newer) post: June 2007 Silverlight Resources
p
Previous (older) post: Acropolis CTP Available
Tab
Move between links and buttons (Shift+Tab to go back)