Creative Jar Blog RSS Feed

List<WhateverObjectYouWant> Stucture

June 2, 2008 14:17 by tim

I'm getting right into using these List<> objects from System.Collections.Specialized.  Very quick compared to DataTables and they can even wrap up your custom objects and make them immediataly bindable to your DataBound controls on the form.  They populate really easily from LINQ queries as well so you can throw your custom strongly-type object around all over the place and everything is tight when compiling :¬)

The only thing i couldn't quite grasp was sorting. Before i saw this ( http://www.jonasjohn.de/snippets/csharp/sort-enumerable-list.htm ), I would resort to going back to DataViews and then using the sort function on there

I think I was missing some syntax knowledge when I looked at this previously but you can use any key on your objects you like, like so :

lstClean.Sort(delegate(LPDataAccess.AgeRange A, LPDataAccess.AgeRange B) { return A.AgeCode.CompareTo(B.AgeCode); });

Damn fine use of delegates there :¬)


Be the first to rate this post

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

Related posts

Calendar

March 2010
SuMoTuWeThFrSa
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910