We are familiar with collection classes because they are often used in projects. Remember that whenever you encounter a key-value pair, you will think of HashTable. You can use it in the process, but you don't know it very well. At noon today, we sorted out related classes, including lists, queues, bit arrays, hash tables, and dictionaries.
(1) ArrayList class: use an array dynamically increased by size as needed.
The above Code gives detailed comments to the methods in the ArrayList class. If you do not understand these methods, you can go to MSDN to check them. The subsequent introduction is basically explained by adding comments to the code.
Code
Class Program
{
Static void Main (string [] args)
{
ArrayList al = new ArrayList ();
Al. Add (100); // Add a single
Foreach (int number in new int [6] {9, 3, 7, 2, 4, 8 })
{
Al. Add (number); // Add group method 1
}
Int [] number2 = new int [2] {11, 12 };
Al. AddRange (number2); // method 2 for adding a group
Al. Remove (3); // Remove 3
Al. RemoveAt (3); // remove 3rd
ArrayList al = new ArrayList (al. GetRange (1, 3); // The new ArrayList takes only one portion of the old ArrayList.
Console. WriteLine ("Traversal method 1 :");
Foreach (int I in al) // do not force convert
{
Console. WriteLine (I); // method 1
}
Console. WriteLine ("Traversal method 2 :");
For (int I = 0; I <al2.Count; I ++) // The array is length
{
Int number = (int) al [I]; // be sure to force convert
Console. WriteLine (number); // method 2
}
}
}
(2) Queue class: Queue, indicating the object's first-in-first-out set. The Enqueue method is used to enter the queue, and the Dequeue method is used to output the queue.