: Adds 10 elements to the collection, computes the average, and calculates the maximum and minimum values.
1 Doublesum =0;2List. AddRange (New int[] {1,2,3,4,5,6,7,8,9 });3 intMax, Min;4Max = Min = (int) list[0];5 6 for(inti =0; I < list. Count; i++)7 {8 //Maximum Value9 if(Max < (int) List[i])Ten { OneMax = (int) List[i +1]; A } - //Minimum Value - Else if(Min > (int) List[i]) the { -Min = (int) list[i]; - } - Else { } +Sum + =convert.todouble (List[i]); - } + for(inti =0; I < list. Count; i++) A { atConsole.Write (List[i] +" "); - } -Console.WriteLine ("\navg = {0}", Sum/list. Count); -Console.WriteLine ("Max = {0}", Max); -Console.WriteLine ("Min = {0}", Min);
: Stores 10 random numbers in a collection without repeating
1Random rd =NewRandom ();2 for(inti =0; I <Ten; i++)3 {4 intn = Rd. Next (0,Ten);5 if(!list. Contains (n))6 {7 list. ADD (n);8 }9 }Ten for(inti =0; I < list. Count; i++) One { A Console.WriteLine (List[i]); -}
Complete.
ArrayList collection-[Exercise]--c#