Quick Method Of Sorting On Multiple Properties

by Jon Davis 24. June 2008 07:37

I’ve started replacing my custom List<T> sorts of

 

ret.Sort(new Comparison(delegate(MyClass o1, MyClass o2) { return o1.City.CompareTo(o2.City); } ) );

 

.., which doesn't seem to support multiple property sorts when I run Sort() multiple times (and I don're care to glean from the many multi-property sort samples on the web that have tens of lines of method execution), with ..

ret = new List<MyClass>(from r in ret orderby r.State, r.City select r);

Works like a charm. I'm slowly learning to dig LINQ-to-Objects ;)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Software Development | C#

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading




 

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Jon Davis (aka "stimpy77") has been a programmer, developer, and consultant for web and Windows software solutions professionally since 1997, with experience ranging from OS and hardware support to DHTML programming to IIS/ASP web apps to Java network programming to Visual Basic applications to C# desktop apps.
 
Software in all forms is also his sole hobby, whether playing PC games or tinkering with programming them. "I was playing Defender on the Commodore 64," he reminisces, "when I decided at the age of 12 or so that I want to be a computer programmer when I grow up."

Jon was previously employed as a senior .NET developer at a very well-known Internet services company whom you're more likely than not to have directly done business with. However, this blog and all of jondavis.net have no affiliation with, and are not representative of, his former employer in any way.

Contact Me 


Tag cloud

Calendar

<<  August 2020  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

View posts in large calendar

RecentPosts