I <3 List

by Jesse 19. September 2007 04:38

I lived under a rock apparently for quite a while, then I discovered the generic list. I’ve come to the conclusion I LOVE lists. I can pass any object, do stuff to it (add, remove, blah blah), its like having a database on tap with all the stored procedures you generally need (update, insert, remove, select, find). In my opinion they stomp arrays outright and they’re FASTER. You can do a String[].sort(delegate, with arrays you can’t! I’ve used lists now to collect a group of entities, find the ones I want (object for object) and dump it out to something useful. I hate arrays, but I <3 List.

So, say you got ton of strings returned from a query and now you need them sorted. Hmm, thats a total hassle with arrays …but lists …well, all you have to do is compare.

List list = new List();
list.Add(”me”);
list.Add(”you”);
list.Add(”they”);
list.Add(”them”);
list.Add(”us”);
//so there’s our list

list.Sort(delegate(string item1, string item2)
{
return (item1.CompareTo(item2));
});

list.ForEach(delegate(string item)
{
Response.Write(item);
});

and now you have a nice, neat sorted list.

Be the first to rate this post

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

Tags:

.Net | C# | Coding

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

Like the description says, at my core, I'm a scientist and engineer.  I came from humble beginnings on a 486DX2 Packard Hell playing doom2 on IPX to in a small time retail shop and got into hardware (ISO layers FTW!) and it was all downhill from there.  I'm infinitely curious about almost everything and always wanting to know.

Some of the stuff I'm currently into/researching...

Sitefinity

Ninject

Subsonic

Java

Currently working on ...
i did the hundred 
and some extra stuff

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's, their brother nor their dog's view in anyway.  At all.  Ever.

© Copyright 2007-2008