In the previous section, when we introduced the data structure of array, we said that it was static, the number of elements per dimension was compiled, and it was uniquely determined, and its type was strongly typed.
So, in this section, we'll talk about another data structure similar to array but overcomes the disadvantage of array: ArrayList.
First of all, it is not static, at compile time the number of elements of each dimension is not specified, the system default element number is 16, when the element increases and is about to be greater than 16 o'clock, it will increase the expansion to 32, in order to increase the regular growth, change the hours, the opposite processing.
Second, the element type is a weak type, object. At run time, depending on the type that is actually given, the type of each element is determined, that is, the elements in this set can be a variety of different elements, mixed-style.
Look first. NET provides the ArrayList interface:
1) object creation and initialization
Object creation ArrayList ArrayList = new ArrayList () {3.14, "vuefine"}; add element arraylist.add ("Hello wolrd"); Arraylist.add (5);
2) Accessing elements
Access Element Object ELE0 = arraylist[0]; Type t0 = Ele0. GetType ();//double
3) Modifying elements
Modify Element arraylist[0] = "Ni Hao";
4) Delete Element
Delete element //Remove existing Object Arraylist.remove (5); Arraylist.removeat (0); Remove objects that do not exist Arraylist.remove (12);//Do not throw exceptions
5) ArrayList and other object relationships
Object cloneal = Arraylist.clone (); Create a shallow copy of Type Tclone = Cloneal.gettype (); Array is abstract and can only be created by static methods array array = Array.CreateInstance (typeof (Object), Arraylist.count); Arraylist.copyto (array);//Copy to array