C # Collection Special Collections

Source: Internet
Author: User

Initialize Hay heap Stack Collection
Advanced after out, an assignment of one, a value of one
Stack ss = new stack ();
add element (push) push
Ss. Push (1);
Ss. Push (2);
Ss. Push (3);
Ss. Push (4);
Ss. Push (5);
Number
Console.WriteLine (ss. Count);
Pop
Console.WriteLine (ss. Pop ());
Simply view, do not eject
Console.WriteLine (ss. Peek ());
foreach (int aa in SS)
{
Console.WriteLine (AA);
}
Emptying the collection
Ss. Clear ();

Console.ReadLine ();


Queue Collection Initialization
FIFO, a value, assignment
Queue que = new queue ();
adding elements
Que. Enqueue (2);
Que. Enqueue (3);
Que. Enqueue (4);
Que. Enqueue (5);
Que. Enqueue (6);
Removed from
Que. Dequeue ();
Number
Console.WriteLine (Que. Count);
Emptying the collection
Que. Clear ();

foreach (int aa in Que)
{
Console.Write (aa+ "\ t");
}

Console.ReadLine ();


Hashtable collection
Advanced after out, an assignment, but only together to take value
Initialization
Hashtable ht = new Hashtable ();
Ht. ADD (1, "Coca-Cola");
Ht. ADD (2, "Sprite");
Ht. ADD (3, "Pepsi");
Ht. ADD (4, "Fanta");
Ht. ADD (5, "US-year");
Remove (an element of the position of a key value)
Ht. Remove (3);
Determine if it contains
Console.WriteLine (HT. Contains (5));
Console.WriteLine (HT. Count);
foreach (int aa in HT. Keys)
{
Console.WriteLine (AA);
}
foreach (String SS in Ht. Values)
{
Console.WriteLine (ss);
}
Use enum type to read (table style)
IDictionaryEnumerator IDE = ht. GetEnumerator ();
while (IDE. MoveNext ())
{
Console.WriteLine (IDE. key+ "\ t" +ide. Value);
}
Console.ReadLine ();

C # Collection Special Collections

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.