First, define a new array class
Class Arraylistjihe
{
static void Main ( string[] args
{
ArrayList arr = new ArrayList ();
arr. ADD (3);
arr. ADD ("Hello");
// Generate a 0-based index by adding an element's order, reading the data through an index
Console.WriteLine (arr[0]);
Console.WriteLine (arr[2]);
}
}
ArrayList must refer to using System.Collections;
Arr. Insert (1,17) //17 This number is inserted at the position of the collection 1
Int[] Shuzu=new int[3]{6,7,8};
Arr. Insertrange (1,shuzu); //split coefficient group, insert array to 1 position
Arr. AddRange (Shuzu); //detach the coefficient group, append the array to the position following the collection
Show all content in a collection
foreach (Object o in arr)
{
Console.WriteLine (O.tostring ());
}
Adding an array entity
Arr. ADD (Shuzu);
int [] newshu= (int[]arr[3]);
foreach (int a in Newshu)
{
Console.WriteLine (a);
}
removing data
Arr. Remove ("Hello"); //Remove the Hello from the first position
Arr. RemoveAt (3); //Remove data at the specified location
Sorting functions for collections
ArrayList arr = new ArrayList ();
for (int i = 0; i < 5; i++)
{
Arr. ADD (int. Parse (Console.ReadLine ()));
}
Arr. Sort (); //Ascending sort
Arr. Reverse (); //Flip the collection
foreach (int a in arr)
{
Console.WriteLine (a);
}
Console.WriteLine (arr. Count); //Returns the number of elements in the collection
Console.WriteLine (arr. IndexOf (14)); //Returns the position of the first 14 in a collection
Console.WriteLine (arr. LastIndexOf (14)); //Returns the position of the last 14 in the collection
2014-12-18 Collection