Stack collection, Queue collection, Hashtable collection

Source: Internet
Author: User

1. Stack: Stack, advanced out, one assignment, one value, in order.

. Count takes the number of elements in the collection

The. push () pushes the element one by one into the collection using the//stack collection. Push ()

Pop () pops a collection of elements

. Clear () empties the collection

New Stack (); // first deposit and then take out            S.push (1);            S.push (2);            S.push (3);             // also available with foreach Loop output            Console.WriteLine (S.pop ());

2.queue: First deposit the first output, one of the assignment of a value, in order.

. Count takes the number of elements in the collection

. Enqueue () into the Queue collection//Deposit element

. Dequeue () Out queue collection

. Clear to empty the collection

// Queue q = new Queue ();             // Q.enqueue (1);             // Q.enqueue (2);             // Q.enqueue (3);             // Console.WriteLine (Q.dequeue ());             // Console.WriteLine (Q.dequeue ());

3.hashtable: Advanced After, one assignment, but only together to take value.

. Add (,) adds key and element//For element addition

. Remove () Removes the element inside the parentheses

. Contains () Determine whether there are bracketed elements in the collection

. Count counts the number of elements in the collection

Hashtable h =NewHashtable (); H.add (1,"SS"); H.add (2,"DD"); foreach(intIinchH.keys)//Output Key{Console.WriteLine (i); } Console.WriteLine ("------"); foreach(stringSinchH.values)//the value that corresponds to the output key{Console.WriteLine (s); } Console.WriteLine ("-----------"); Console.WriteLine (h.count);//Enter the number of elements altogether            

Stack collection, Queue collection, Hashtable collection

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.