Question : .net generic collection vs hashtable

I have a collection of objects that I store in a hashtable so I can find each object using a key.  Is this necessary?  Is there a way to just search a collection without using a hash?

I can always just loop through it, but which is more efficient?

below is some suedo code that I am using.  It shows how I add my object to the hash and how I get it back out.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
class item{
int id
string title
}

//loop though collection to create hash
foreach(singleitem in itemscollection
myhash.add(singlitem.id, singleitem)

//get the object out of the hash
if (myhash.containskey(someid))
   dosomething( (item) myhash[someid])

Answer : .net generic collection vs hashtable

I think a KeyedCollection would work for you.l

http://msdn.microsoft.com/en-us/library/ms132438.aspx
Random Solutions  
 
programming4us programming4us