Special Collections: Queue, Stack one, stack stack class: Advanced, no index
New Stack ();
1. Add data: Push: Pushes elements into the collection
Ss. Push (3); SS. Push (5); SS. Push (7);
2. Get the data:
(1) Peek returns the object at the top of the stack without removing it (gets the value of the last entered element)
Console.WriteLine (ss. Peek ()); // 7
(2) Pop sets the elements together (read and remove)
Console.WriteLine (ss. Pop ()); // 7 Console.WriteLine (ss. Pop ()); // 5
3. Other operations
ToArray: Returns the array type, converts the elements in the stack to a collection, and then puts them in the array
Object [] Shuzu = (object[]) ss. ToArray (); foreach (object in Shuzu) {Console.WriteLine (a);}
Queuing Queue class: FIFO
1, the definition method:
New Queue ();
2. Increase:
(1) Enqueue put elements at the end of the queue
Q.enqueue (3); Q.enqueue (5); Q.enqueue (7);
(2) Peek: Returns the object at the beginning without removing it
Console.WriteLine ("Peek:"+q.peek ()); // 3
3. Get: Dequeue Remove and return the object at the beginning of the queue
Console.WriteLine ("Dequeue:"+q.dequeue ());
Hash table Hashtable Class
Reading data in pairs with key values, you can set the index yourself
Hashtable ht = new Hashtable (); Ht. ADD ( a , " zhangsan ); // an arbitrary type of key + an arbitrary type of value ht. ADD ( " ", " lisi ); Ht. ADD ( c , " wangwu );
How to print the number of elements in a hash table:
ICollection Htkeys = ht. Keys; Console.WriteLine (Htkeys. Count);
Read key value
// CopyTo---Copied to an array string New string [3];htkeys. CopyTo (SS1,0);
Reading value values
ICollection htvalues = ht. Values; string New string [3];htvalues. CopyTo (SS2,0);
Paired reads: Both key and value need to be redefined
IDictionaryEnumerator ID = ht. GetEnumerator (); // Object Key1=id. Key; // gets a value // object value1 = ID. Value; // ID. MoveNext (); // moves down one element, returns a Boolean value, and can no longer be moved if False while (ID. MoveNext ()) {object key2=ID. Key; Console.WriteLine (Key2. ToString ()); object value2 = ID. Value; Console.WriteLine (value2. ToString ());}
Ht. Remove ("B"); --Remove the key based on the key value
11. C # Basic finishing (special collections and hash tables)