First, ArrayList collection review//definitionArrayList Al =NewArrayList (); //adding elementsAl. ADD (2); //inserting elementsAl. Insert (1,3); //View number intA = al. Count;//the meaning of count number//emptying the collectional. Clear (); //Clone a collectional. Clone (); //determine whether a value is included BOOLb = al. Contains ("2"); //View 3 The first occurrence of an index number intC = al. IndexOf (3); //View 3 The last occurrence of an index number intD = al. LastIndexOf (3); //Remove 3 of this dataAl. Remove (3); //Remove data with index number 3Al. RemoveAt (3); //sort, automatically in ascending orderal. Sort (); //flips the collection, which is sorted in descending orderAl. Reverse ();
Second, special set
//Stack collection of hay stacks//advanced after the assignment of one to one value//How to define//stack aa = new stack (); ////push elements within the collection //AA. Push (1); //AA. Push (2); //AA. Push (3); //AA. Push (4); //AA. Push (5); ////pop as long as the element is ejected, there is no one in the collection.////console.write (aa. Pop ()); ////peek () Just take a look and don't remove //Console.WriteLine (aa. Peek ()); ////Empty Collection //AA. Clear (); ////Clone //stack bb = new stack (); //bb= (Stack) AA. Clone (); ////Traversal set go ahead and print it backwards //foreach (object aaa in AA)//{ //Console.WriteLine (AAA); //} //Queue Queues Collection//Advanced First Out one assignment one value//How to define//queue que = new queue (); //Add Data//Que. Enqueue (1); //Que. Enqueue (2); //Que. Enqueue (3); //Que. Enqueue (4); //Que. Enqueue (5); //Removing a data//Console.WriteLine (Que. Dequeue ()); //Peek () take the data and look at it.//Console.WriteLine (Que. Peek ()); //iterating through the collection//foreach (Object aa in Que)//{ //Console.WriteLine (AA); //} //Hashtable Hash Table//advanced after out, one assignment, but only together to take the value,Hashtable HT =NewHashtable (); Ht. ADD (0,"Zhang San"); Ht. ADD (1,"John Doe"); Ht. ADD (2,"Harry"); Ht. ADD (3,"Zhao Liu"); Ht. ADD (4,"Feng Qi"); //removing a key value and value//ht. Remove (2); //determine if it contains//Console.WriteLine (HT. Contains (2)); //iterating through the collection//similar to stack collection, reverse print foreach(intIinchht. Keys) {Console.WriteLine (i); } foreach(stringSinchht. Values) {Console.WriteLine (s); }
three, enum type
// // idictiona Ryenumerator ID = ht. GetEnumerator (); // Gets the inside of each key value and value values that need to be looped to print // while (ID. MoveNext ()) // move to the next key and value // { Console.WriteLine (ID. Key + "\ T" + ID. Value); // }
Iv. Exercises:
//Enter the number of classes, according to the number of people to create an array set, first save the name, followed by the score//printed out, like a table, preceded by a name, followed by scoresConsole.Write ("Please enter the number of classes:"); ArrayList Al=NewArrayList (); intn=int. Parse (Console.ReadLine ()); for(inti =0; I < n; i++) {Console.Write ("Please enter"+ (i+1)+"name of individual:"); stringXM =(Console.ReadLine ()); Al. ADD (XM);//it means to store the input elements in the collection.Console.Write ("Please enter"+ (i+1)+"a score:"); DoubleFenshu =Double. Parse (Console.ReadLine ()); Al. ADD (Fenshu); } Console.WriteLine ("name"+"\ t"+"score"); //because in the front really is input double element 2*n, so here i<2*n, i+=2 meaning is a row of two factors, the next line is the third fourth factor, so is i=i+2 for(inti =0; I < n2; i+=2) {Console.WriteLine (Al[i]+"\ t"+al[i+1]); } console.readline ();
May 11 ArrayList Collection Review, special sets, enumeration types