The returned value of the Hashtable type is suddenly used. I suddenly thought of ArryList. As a comparison, I will summarize it.1. HashTabelIn. NET Framework, Hashtable isSystem. CollectionsProvided by the namespaceCollection object,It is also a variable-length array used to process and display key-value pairs similar to key/value. The key is usually used for quick search, and the key is case sensitive; value is used to store the value corresponding to the key. In Hashtable, key/value pairs are of the object type, so Hashtable can support any type of key/value pairs ..Simple operations on Hash TablesAdd a key/value key-value pair to the hash table: HashtableObject. add (key, value); remove a key/value key-value pair in the hash table: HashtableObject. remove (key); Remove all elements from the hash table: HashtableObject. clear (); checks whether the hash table contains the key HashtableObject. contains (key); for example: Hashtable ht = new Hashtable (); Ht. add (×, × )... ...Traverse a hash tableUsed to traverse a hash tableDictionaryEntryObject, the Code is as follows: foreach (DictionaryEntry de in ht) // ht is a Hashtable instance {Console. writeLine (de. key); // de. the Key corresponds to the key/value pair key Console. writeLine (de. value); // de. key corresponds to key/value Key-value Pair value}2. ArryList (Array List)The ArrayList object is a variable-length array. You can add elements as needed. you can use the ArrayList method to add or retrieve elements to the array list and modify an element. for example, ArrayList MyArrayList = new ArrayList (); MyArrayList. add ("Caoxi"); MyArrayList. clear ();
All objects retrieved from ArrayList are of the object type. Before using ArrayList, convert them to an appropriate type. arrayList theArrayList = new ArrayList (); theArrayList. add ("1"); theArrayList. add ("2"); string s = (string) theArrayList [0]; string s1 = (string) theArrayList [1]; pay attention to Contains () if ArrayList contains objects provided by parameters, true is returned. Otherwise, falseif (theArrayList. contains ("1") // determines whether the character "1" exists in the ArrayList
Another usage of ArryList:
ArrayList objAry = new ArrayList ();
ObjAry = (ArrayList) Application ["users"]; // Application ["users"] is the object that stores users and converts them to ArryList objects.
ObjAry.Add(this.txt Name. Text); // Add the current user
Application. Lock (); // Lock the object to prevent other users from logging on at the same time
Application ["users"] = objAry; // This Application ["users"] has joined the current user.
Application. UnLock (); // UnLock
// Retrieve data
ArrayList objAry = (ArrayList) Application ["users"];
For (int I = 0; I <objAry. Count; I ++)
{
StrOnLine + = "<B>" + objAry [I]. ToString () + "</B> <BR> ";
}
Response. Write (strOnLine );