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