Jordan,
I'm glad that you see that this is probably a premature optimization
issue. However, that doesn't mean that you can't discuss it in a
theoretical sense.
Personally, choosing a data structure when I am initially coding a
solution isn't about the number of items that will be in the data structure,
but rather, what I need the data structure to do. A list and a dictionary
are two different things.
A dictionary is used when you need to perform lookups using some sort of
key. A list is used when you have a set (I use this term loosely, not in
the strict mathematical sense) of items. These items could possibly have a
key to be looked up on, but the list isn't concerned about that, it's really
just a simple container.
That being said, because you have a specific need for looking up an
object based on a key, I would day that the proper choice is the dictionary.
Of course, after you code and you start doing performance evaluations,
if you find that this is a major bottleneck, then yes, I would try other
solutions, but at this level, I would take clear, concise, understandable
and easily maintained code over code that is micro-optimized.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Jordan" <jn****@hotmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
>I want to store small collections of objects that have a unique id
string:"Name", so I opted to use a Dictionary<string,MyObject>
collection. However, since my collection will rarely exceed 10 or 12
items, would I be better of just using a regular List<MyObjectand
looping through the Names to find an object?
I know it's probably splitting hairs from a performance standpoint,
but I'm curious from a theoretical standpoint.
Jordan