Actually, Dictionary<,>
is often slower than a linear search, due to the inherent complexities of doing the dictionary logic (haches, buckets, etc). In my tests, the cutoff (where Dictionary<,>
starts being faster) is often around 150 elements. And since you generally have a lot fewer tables than 150, I'd be happy with a linear list for performance.
(which doesn't at all mean "don't use Dictionary<T>
; it just means that performance might not be the main reason for this particular use-case; the unique key enforcement and the foo["bar"] model might be)
Part of this is due to the complexity of getting the hash - the GetHashCode()
for string
in particular is relatively expensive (although int.GetHashCode()
is blindingly fast ;-p).
In reality, in most small sets of data you will never notice the difference between the two. If you have large data, then obviously you need to plan for that and code accordingly.
Other differences between a Dictionary<,>
and something like a List<>
is things like uniqueness: a Dictionary<,>
won't let you have duplicated keys (although a Lookup<,>
in .NET 3.5 will).