I’m very much enjoying David Fowler’s tweets, and since he doesn’t have a blog, I will continue to share and expand on his wisdom so that it might reach a larger audience. He points out that “.NET has 4 built-in dictionary/map types [and] there’s no guidance on when to use what, mostly individual documentation on each implementation.”
There is actually some good documentation on C# Collections and Data Structures here that we can compare and combine with David’s good advice as well!
Definitely important to remember. Generics have been around since .NET Framework 2.0 around 15 years ago so this is a good reason to consider avoiding Hashtable and using Dictionary<> instead. Hashtable is weakly typed and while it allows you to have keys that map to different kinds of objects which may seem attractive at first, you’ll need to “box” the objects up and boxing and unboxing is expensive. You’ll almost always want to use Dictionary instead. If you’re accessing your collection across threads, consider the System.Collections.Concurrent namespace or using System.Collections.Immutable which is thread-safe because you’ll always be working on a copy as the original collection is immutable (not modifiable). David says this about
Or perhaps
Another one that isn’t often used but I’ll add as it’s good to know about is
This is great advice from David:
Measure and test, measure and test. Good luck to you! Sponsor: Make login Auth0’s problem. Not yours. Provide the convenient login features your customers want, like social login, multi-factor authentication, single sign-on, passwordless, and more. Get started for free. © 2021 Scott Hanselman. All rights reserved. Differences between Hashtable vs Dictonary vs ConcurrentDictionary vs ImmutableDictionary published first on http://7elementswd.tumblr.com/ via Tumblr Differences between Hashtable vs Dictonary vs ConcurrentDictionary vs ImmutableDictionary
0 Comments
Leave a Reply. |
About UsIf you want to keep up with the latest in web design, you have to be willing to study and learn on an ongoing basis. If you are a web developer or web designer, you’ll find a lot of useful tutorials and code snippets collection here. Furthermore, we also discuss more general topics of web design and how the role of a web designer has evolved over the years.
|