C # Foundation Special Collection

Source: Internet
Author: User

One

Stack: Stank, FIFO, an assignment, one value, in order.

. Count takes the number of elements in the collection

. Push pushes elements one by one into the collection

Pop sets the element one pop-up collection

. Peek to view an element in a collection

. Clear to empty the collection

Stack st=new stack (); Hay Heap Set initialization

St. Push (0); push-in

St. Pop ();

St. Clear (); clear

Two

Queue collection: Queues, FIFO, an assignment, one value, in order.

. Count takes the number of elements in the collection

. Enqueue into the queue collection

. Dequeue Out Queue Collection

. Peek to view an element in a collection

. Clear to empty the collection

Example a : This collection is not indexed, first go in first

Queue que = new queue (); initialize

Que. Enqueue (0);
Que. Dequeue (); out

Example two : Calculates how many elements are in a collection

int N=que. Count: Counts the number of elements in the collection

shown example Three : Determines whether there is an element in the queue collection

Que. Contains (0); Whether it contains this element

Three

Hash table: Hashtable, advanced out, one assignment, together to value.

Properties and methods:

. Add (,) adds key and element

. 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

Example one: establishment, assignment, and reading of theHashtable hash table

Using a hash table, initialize first: Hashtable hs = new Hashtable ();

Ht.  ADD (0, "Zhang San"); When assigning a value, the keys in the front of the comma are the object class, and the comma is followed by values

Example two: Remove an element and keyanddetermine if there is an element and key in the collection

Ht. Remove (0) remove element with key value 0

Ht. Contains (0); Determines whether the set contains an element with a key value of 0

Example three: Calculates how many elements are in a Hashtable collection. A separate empty statement is attached

int N=HT. Count; Calculate how many elements are in a collection

Ht. Clear (); empty all elements of a set

Example four: Reading keys and elements from a Hashtable collection with an enumeration type

IDictionaryEnumerator IDE = ht. GetEnumerator ();

while (IDE. MoveNext ())
{
Console.WriteLine (IDE. Key+ "" +ide. Value);
}

Read all the contents of the hash table

C # Foundation Special 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.