Ideally we should avoid using Hashtable where possible because thanks to generics, Dictionary, is more efficient. This is because Dictionary does not have to box and unbox the values. If you're not familiar with this you can reference this article. http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx Dictionary is also a type safe way of storing and retrieving data and therefore should be preferred so as to avoid experiencing run time errors.
There are actually multiple types of dictionaries available:
- ConcurrentDictionary - thread safe (can be safely accessed from several threads concurrently)
- HybridDictionary - optimized performance (for few items and also for many items)
- OrderedDictionary - values can be accessed via int index (by order in which items were added)
- SortedDictionary - items automatically sorted by key
- StringDictionary - strongly typed and optimized for strings
There are other data structures out there in c# that can be really effective. I highly recommend you read this article multiple times when you get the chance. It's a little dated (.Net 2.0) http://msdn.microsoft.com/en-us/libr...1%28v=vs.80%29 But it's really good and dives deep into how each of the core data structures work.
One of the engineers I work with pointed out something else that's pretty awesome. KeyedCollection, here's what he had to say:
The KeyedCollection uses a Dictionary internally. It is another nice way of managing keyed data.
http://msdn.microsoft.com/en-us/library/ms132438.aspx
http://stackoverflow.com/questions/7...eyedcollection
No comments:
Post a Comment