C # collection class

Source: Internet
Author: User

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.

 

Related Article

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.