简体   繁体   中英

Hashtable vs Dictionary

My understanding is that Dictionary does not have boxing issues and faster in performance . Are there cases that the usage of Hashtable would be more advisable compared to Dictionary? Thanks

For.Net 2.0, you pretty much always want Dictionary. However, be warned that it's not just a "drop in replacement" for an existing Hashtable. There are some differences in the way they work (mostly how they handle nulls) that mean you do need to check your code first.

Hashtable is pretty much deprecated. It might be useful for interfacing with legacy code.

Dictionary is a generic class introduced in .NET 2.0, along with other classes in System.Collections.Generic namespace. They supersede classes in System.Collections namespace.

The main advantage of HashTable is that you can use it and target .NET < 2.0.

Otherwise, Dictionary<T,Y> (used correctly) is pretty much better in every way.

Here is What i know

1) Dictionary stores in key value pairs 2) Hastable also stores in key value pairs but uses a hash key to probe the contents.

So if i were to decide what to use, Should i use hashtable if my collection is huge and i want to search for a certain item? And use dictionary if the collection is not so huge?

Also a followup question is, in c#, hastable does not do chaining like in c or c++ is this correct?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM