C # Collection Related
. Count//Get the number of collection elements
. Contains ()//Determine if an element exists in the collection
. Sort ()//ascending sort
. Reverse ()//Flip the entire set, collocation. Sort () to enable descending sorting
Set Features:
You do not need to specify the number of elements, the array needs to specify the number. The collection has only one dimension, and the array can be multidimensional.
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Collections;
Using System.Collections.Specialized;
Namespace Collection
{
Class Program
{
static void Main (string[] args)
{
Console.Write ("Please enter the number of people:");
int a = Int. Parse (Console.ReadLine ());
ArrayList x = new ArrayList ();
int sum = 0;
for (int i = 0; i < A; i++)
//{
Console.Write ("Please enter {0} personal score:", i+1);
X.add (int. Parse (Console.ReadLine ()));
sum+= (int) x[i];
//}
X.sort ();
Console.WriteLine ("Average divided into:" +sum/a);
Console.WriteLine ("Maximum:" + (int) x[a-1]);
Console.WriteLine ("Lowest divided into:" + (int) x[0]);
Console.ReadLine ();
Console.Write ("Please enter the number of people:");
int a = Int. Parse (Console.ReadLine ());
ArrayList JH = new ArrayList ();
for (int i = 0; i < A; i++)
//{
Console.WriteLine ("Please enter the first name of {0} person:", i+1);
Jh. ADD (Console.ReadLine ());
Console.WriteLine ("Please enter the age of the person {0}:", i + 1);
Jh. ADD (int. Parse ((Console.ReadLine ()));
//}
for (int i =1; i < a*2; i=i+2)
//{
for (int j = i; j < a*2-2; j=j+2)
// {
if (int. Parse (Jh[i]. ToString ()) <int. Parse (jh[j+2]. ToString ()))
// {
int huan = 0;
Huan = (int) jh[i];
Jh[i] = (int) jh[j+2];
Jh[j+2] = Huan;
String o = "";
o = (string) jh[i-1];
JH[I-1] = jh[j+1];
Jh[j + 1] = O;
// }
// }
//}
int z=0;
int v=1;
for (int i = 0; i < A; i++)
//{
Console.WriteLine ("Name:" +jh[z]);
Console.WriteLine ("Age:" +jh[v]);
Z = z + 2;
v = v + 2;
//}
Console.WriteLine ("Age Max" +jh[0]);
Console.ReadLine ();
foreach (Object aa in JH)//Traversal Collection
//{
//}
Iterating through an array
int[] array = new int[] {2, 3, 4, 5, 6, 7, 8, 9, 2};
foreach (int aa in array)
//{
Console.WriteLine (AA);
//}
Console.ReadLine ();
}
}
}
Written today
2016/06/27