Set (no indexes are available for Stack, queue, or hashtable)

Source: Internet
Author: User

/*//Set StackNo index! "LikeDead end"

Stack S = new stack ();// Special Collection heap!First-in-first-out and later-in-first-out!

S. Push ("1"); // use "" for the assignment content

S. Push ("2 ");

S. Push ("3 ");

S. Push ("4 ");

S. Push ("5 ");

// Console. writeline (S. [2]); indexes cannot be used []

Foreach (string a in S) // obtain data in sequence based on the collection structure! // To read the set, use foreach ()

{Console. writeline ();}

Stack Fuzhi = (stack) S. Clone (); // Copy Stack set S

String tanchu =S. Pop (). tostring (); // pop up and remove the last added character in the set.Pay attention to the writing () format!

String Chakan =S. Peek (). tostring (); // read but not remove. The last added element ,!

// S. Clear (); // indicates clearing the set!

Console. writeline (S. Count);// Returns the int value to obtain the number of elements in the set.

// Console. writeline (s [1]); // the elements in the set cannot be read at this time.Stack has no index!

Console. Readline ();*/

/*//Queue queue, no index"Pay in line"

Queue q = new Queue (); // only the first-in-first-out queue is supported!

Q. enqueue (3 );

Q. enqueue (4 );

Q. enqueue (8 );

Q. enqueue (2 );

// Int B = Q [2];The queue has no index and cannot use [] to retrieve the elements in the set!

Foreach (int A in Q)

{Console. writeline ();}

Int Zhi = int. parse (Q. Peek (). tostring ()); // Read only the first element in the queue and do not remove it!

Console. writeline (zhi );

Bool c =Q. Contains (8); // determines whether the queue set contains Element 8.

Console. writeline (c); // output is required to display. ture or flase.

Int Yichu = int. parse(Q. dequeue (). tostring (); // remove the first queue element "delect queue"

Console. writeline (Yichu); // at this time, the output here is 3

Console. writeline ("the new queue collection H :");

Queue H = Q;

Foreach (int d in H)

{Console. Write (d);} // The first element 3 in Q has been removed.

Console. Readline ();*/

//HashtableThe hash table contains keys and values. No index!

Hashtable H = new hashtable ();//No Index,You cannot use [] References. You can write the preceding numbers as needed.!

H. Add (0, "Wang Chao"); // Add an element to the hash table!H. add (1, "fan lei"); H. add (2, ""); H. add (3, "Wang reei"); H. add (4, "Rural green"); H. add (5, "Liu Chunli"); H. add (6, "Sun Qi"); H. add (7, "Meng Xiangxiang"); H. add (8, "Zhu xiaopu ");

Idictionaryenumerator ide = H. getenumerator ();

While (IDE. movenext ())

{

Console. writeline (IDE. Key + "" + ide. Value); // output '0 Wang Chao 'in turn.

}

 

Arraylist AA = new arraylist ();

Foreach (int A in H. Keys) // read the expression format. H. Keys/Values

{

Console. writeline ("in the H set:" + a); // read separately,It's like a collection of two stacks! First in and then out!

AA. Add ();

}

Foreach (int f in aa)

{Console. writeline ("AA set:" + F);} // print the arraylist set AA

Arraylist AAA = new arraylist ();

Foreach (string B in H. values)

{

Console. writeline ("in the H set:" + B );

AAA. Add (B); // The output content is consistent with the value output by hashtable.

}

Foreach (string R in AAA)// Make sure that the element types are consistent during foreach listing! String

{Console. writeline ("in AAA set:" + r );}

H. Remove (4); // remove. Remove the files according to the Keys value in. Here we remove (4, rural green )!

Console. writeline (H. Contains (66); // checks whether the keys key contains 66 and returns the bool value. 

Int Geshu = H. Count; // Number of hashtable Elements

Console. writeline ("number of elements:" + Geshu );

// H. Clear (); // clear hashtable

Hashtable HH = h;

Foreach (Int FIn HH. Keys) // read the expression format. H. Keys/Values

{Console. writeline (f); // read separately,It's like a collection of two stacks! Inbound and Outbound! }

Foreach (String JIn HH. Values)

{Console. writeline (j );}

Console. Readline ();

Set (no indexes are available for Stack, queue, or hashtable)

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.