Alex Rivera | Logout

Should I use a Dictionary for collections with 10 items or less, or is there a better alternative?

Asked 2010-03-10T18:42:45.547
20

I have a list of objects and I need to find an object as quickly as possible (by it's name property). What data-structure should I use? I know I can use a Dictionary, but there wont ever be more than 10 items in the list, and if I remember correctly the dictionary is implemented as an array if the collection contains 10 items or less.

Thanks.

Edit
Report

1 Answer

13

MSDN recommends the ListDictionary for collections with 10 items or less:

This is a simple implementation of IDictionary using a singly linked list. It is smaller and faster than a Hashtable if the number of elements is 10 or less. This should not be used if performance is important for large numbers of elements.

answered 2010-03-10T18:47:52.733

Your Answer