usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Collections;namespace_18 Collection of exercises {classProgram {Static voidMain (string[] args) { #regionCreate a collection that adds numbers, averages and values, and a maximum and minimum value//ArrayList list = new ArrayList (); //list. AddRange (New int[] {1, 2, 3, 4, 5}); //int sum = 0; //int max = (int) list[0]; //int min = (int) list[0]; //for (int i = 0; i < list. Count; i++)//{ //if ((int) list[i] > Max)// { //max = (int) list[i]; // } //sum + = (int) list[i]; //} //Console.WriteLine ("The sum of the numbers in this set is {0}, the average is {1}, the maximum value is {2}", Sum, sum/list.) Count, Max); //Console.readkey (); #endregion #regionWrite a set of length 10, which requires that 10 numbers (0-9) be stored randomly, requiring all numbers not to be duplicatedArrayList List=NewArrayList (); Random R=NewRandom (); for(inti =0; I <Ten; i++) { intRnumber = R.next (0, -); //indicates that there is no random number in the collection if(!list. Contains (Rnumber)) {list. ADD (Rnumber); } Else//indicates that there is no random number in the collection { //once a repeating random number is generated, this cycle does not count, so i--i--; } } for(inti =0; I < list. Count; i++) {Console.WriteLine (list[i]); } console.readkey (); #endregion } }}
ArrayList collection is not commonly used at present, because although it is convenient to store data, it is too cumbersome to extract.
. NET Learning notes----2015-06-24 (ArrayList collection Exercise)