Types of C # key-value pairs

Source: Internet
Author: User

A C # key-value pair class has the following classes:

①idictionary<string, object> IDC = new dictionary<string, object> ();

②keyvaluepair<string, object> par = (keyvaluepair<string, object>) Shoplistcombobox.selecteditem;

③hashtable ht=new Hashtable (); File creates a Hashtable instance ht. Add (e,e); adding keyvalue key-value pairs

Each set of objects within the Hashtable is a dictionaryentry for example we want to loop Hashtable foreach (DictionaryEntry de in myhashtable) {...} Hashtable is a collection of dictionaryentry.

Two KeyValuePair and hashtable differences

KeyValuePair is a single key-value pair object, and Hashtable is a collection.

The KeyValuePair is used to receive Combox selected values.

For example: keyvaluepair<string, object> par = (keyvaluepair<string, object>) Shoplistcombobox.selecteditem;

The difference between three Hashtable and dictionary

1: Dictionary is recommended in single-threaded applications, with a generic advantage, with faster read speeds and fuller capacity utilization.

2: The recommended use of Hashtable in multithreaded programs, the default Hashtable allows single-threaded writes, multithreaded reads, and Hashtable further calls to the Synchronized () method to obtain a fully thread-safe type. While Dictionary is non-thread-safe, it must be protected by the use of the lock statement, and the efficiency is greatly reduced.

3:dictionary has the ability to arrange data in the order in which they are inserted (note: But the order is disrupted when the call to remove () is removed), so it is convenient to use Dictionary in situations where the order needs to be reflected.

Types of C # key-value pairs

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.