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.