C # common methods of dynamic array ArrayList,
Dynamic Array
Dynamic addition and reduction of elements enable the ICollection and List and IEnumerable interfaces to flexibly set insecure array size Collection types. When the elements are value-type, the timeliness rate is not high (resulting in inefficiency due to packing and unpacking ). high)
Common ArrayList Methods
//to create an ArrayListArrayList arrayList = new ArrayList();//to add valuesarrayList.Add(32);arrayList.Add("Puma");arrayList.Add('a');//ArrayList can have different kinds of type of value//to outputforeach (object obj in arrayList){Console.Write(obj + " ");}Console.WriteLine();//show the capacityConsole.WriteLine("the Capacity is:" + arrayList.Capacity);Console.WriteLine("Adding one more element");arrayList.Add(5);Console.WriteLine("Now the Capacity is:" + arrayList.Capacity);//count: gets the number of elements actually contained in ArrayListConsole.WriteLine("The elements in the ArrayList are:" + arrayList.Count);//contains : Determines whether an element is in the ArrayListif(arrayList.Contains(32))Console.WriteLine("It exists!");elseConsole.WriteLine("It doesn'n exist");//Insert: Insert an element into ArrayList at the specified indexarrayList.Insert(2,"real");foreach (object obj in arrayList){Console.Write(obj + " ");}Console.WriteLine();//IndexOf:searches for the specified object and returns the zero-based index of the first occurrence within the entire ArrayList.Console.WriteLine(arrayList.IndexOf(32));//Remove:Removes the first occurrence of a specific object from the ArrayListarrayList.Remove(32);foreach (object obj in arrayList){Console.Write(obj + " ");}Console.WriteLine();//Reverse:Reverses the order of the elements in the entire ArrayListarrayList.Reverse();foreach (object obj in arrayList){Console.Write(obj + " ");}Console.WriteLine();//Sort:Sorts the elements in the entire ArrayList.arrayList.Add(3);arrayList.Add(42);arrayList.Remove("Puma");arrayList.Remove("real");arrayList.Remove('a');//before sortingforeach (object obj in arrayList){Console.Write(obj + " ");}Console.WriteLine();arrayList.Sort();//after sortingforeach (object obj in arrayList){Console.Write(obj + " ");}Console.WriteLine();