Some similarities and differences of dictionary and Hashtable

Source: Internet
Author: User

Dictionaryand Hashtable differences:

and difference Hashtable Dictionary
Dictionary Hashtable
Support Paradigm Not supported
Need to do thread synchronization yourself Thread-safe types can be obtained by calling the Synchronized () method
Enum type is KeyValuePair Enumeration type isDictionaryEntry
. Net 2.0 starts with . Net 1.0 starts with
Under the System.Collections.Generic namespace Under the system.collections namespace
Throws an exception when getting the same nonexistent key Returns NULL when getting the same nonexistent key
Value types do not need to be boxed/unboxing and may be faster Value type values types need to be boxed/unboxing boxing/unboxing

Same point :

Internal is hashtable implementation, through key access to data faster

Need to be immutable, the only key

Key all need to have their ownGetHashCode()方法

 

other similar. Net collections (for alternative Dictionary和Hashtable的 alternatives)

ConcurrentDictionary-For multi-concurrency, thread-safe dictionaries

Under the Hybriddictionary-system.collections.specialized namespace, performance is optimized (when the collection is small, use listdictionary to implement IDictionary, and then when the collection becomes larger, Switch to Hashtable. )

Under the Ordereddictionary-system.collections.specialized namespace, the value can be accessed by a numeric index because the element is already specified when it is added. public void Insert (int index, object key, object value);

SortedDictionary-Automatically sorted when an element is inserted

Under the Stringdictionary-system.collections.specialized namespace, the keys and values are strongly typed as strings rather than objects, and the corresponding optimizations are made.

Some similarities and differences of dictionary and Hashtable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.