Thursday, August 8, 2013

Sort a List of T in C#. (hardcore version)

Note, that reversing a and b like so...

list.Sort((b, a) =>

...here will reverse the order. If FriendlyName held a string value for the names of the three (four) stooges, then then their names would end up sorted in a decending manner like so:

  1. Shemp
  2. Moe
  3. Larry
  4. Curly

 
 

However they would come out in the original example like this:

  1. Curly
  2. Larry
  3. Moe
  4. Shemp

 
 

Get it? If another sort statement came before the stooge sorting then the collection would primarily be sorted by FriendlyName and secondarily be sorted by the other item.

No comments:

Post a Comment