Solution to the length problem of C # ARRAYLISTD
Namespace Arraylistd length Problem {class Program {static void Main (string[] args) {//required parameter is object type ALT+SHIFT+F10 Add reference using System.Collections; ArrayList list = new ArrayList (); Count represents the number of elements that are actually contained in the collection//capity the number of elements that can be contained in the collection//exceeds the number of inclusions, the collection will open up a space list for more than one time in memory. ADD (2); List. ADD (1); List. ADD (2); List. ADD (3); List. ADD (4); List. RemoveAt (0);//Remove the element list at an index location. Sort ();//123456//list. Reverse ();//654321 list. TrimToSize ();//If you add this, list. Capacity this is the actual number of elements, not 4,8,12 the list. ToArray (); foreach (var item in list) {Console.WriteLine (item); }//list. Clear ();//the BOOL b= list is cleared after all elements. Contains (1);//See if the element contains an element 1 Console.WriteLine (list. Count);//1-2 Console.WriteLine (list. capacity);//capacity This attribute is that more than four elements become 8, more than 8 becomes a Console.WriteLine (b); Console.readkey ();} }}===================================================namespace ArrayList Exercise {class Program {static void Main (str Ing[] args) {#region add.list ()///Is not a static class, you can create an object///collection: A collection of many data///collections Benefits: Arbitrary length change, type not fixed////Array length immutable, type single//ArrayList List = new ArrayList ();//List.add (0);//This Land Square put anything can//list.add (3.14);//List.add ("Zhangsan");//List.add (TRUE);//List.ad D (' C ');//List.add (new int[]{1,2,3,4,5});//person P = new person ();//List.add (P);//Custom Class The object is put in////list.add (List),//for (int i = 0; i < List.count; i++)//{//list[i] can Replace the person type//if (List[i] is person)//{////(person) list[i]). Say ();// }//Console.WriteLine (List[i]),//else if (List[i] is int[])// { Reload to int[] Type//for (int j = 0; J < ((int[]) list[i]). Length; J + +)//{//Console.WriteLine (((int[]) list[i]) [j]);//}// }//else//{//Console.WriteLine (List[i]);//}/ /}//Console.readkey (); #endregion ArrayList List = new ArrayList (); Add a single element list.add (1); List.add (2); List.add (6); List.add (0); List.add ("Zhang San"); Add Collection List.addrange (new int[]{1,2,3,4,5,6,7}); Remember that the length of the list in Arrayli is with the count base, not the length//remove element//list.clear ();//Clear All elements//list.remove (1);//Remove A single element, who is written in parentheses to delete who//list.removeat (0),///According to the subscript to delete the element, the 1 is subscript 1 is Zahngsan//List.removerange (0,4); or in accordance with the subscript to start removing the meaning is to delete from the No. 0 subscript Delete 2 elements//After 4, the previous single element is deleted after the deletion of the elements in the array//list.sort ();//LCont.//List.reverse ();//invert//INSERT into the element to be inserted, followed by no type requiring list.insert (1, "I am inserted"); Insert into the specified position index List.insertrange (1,new string[]{"John Doe, old Five, Zhao Liu"}); Determines whether a specified element is included, and the bool type is used to receive the bool B = list.contains ("I am inserted"); Console.WriteLine (b); if (! List.contains ("Pig")) {List.add ("pig"); } else {Console.WriteLine ("PPP"); }for (int i = 0; i < List.count; i++) {//output also outputs each element List[i] Console.WriteLine (Li St[i]); } console.readkey (); }} public class man {public static void Say () {Console.WriteLine ("I am Human"); } }}