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.
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.
You may want to consider the System.Collections.Specialized.ListDictionary
if you are certain there will be less than ten items.
Also consider the System.Collections.Specialized.HybridDictionary
which switches behaviour (with a small overhead) should the size increase above a threshold, handy if your assumption is wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With