List. count//gets the number of actual elements in the collection.
List. capacity//gets the number of elements that can be contained in the collection.
/**
* When the number of elements actually contained in the collection (Count) exceeds the number of elements that can be contained (capacity), the collection will open up one more space to the memory to ensure that the length of the collection is sufficient.
**/
Code:
1 Static voidMain (string[] args)2 {3 //instantiate a Collection object4ArrayList list =NewArrayList ();5 6List. ADD (1);7 8 Console.WriteLine (list. Count);9 Console.WriteLine (list. capacity);Ten Console.readkey (); One}
Run:
Code:
1 Static voidMain (string[] args)2 {3 //instantiate a Collection object4ArrayList list =NewArrayList ();5 6List. ADD (1);7List. ADD (2);8List. ADD (3);9List. ADD (4);TenList. ADD (5); One A Console.WriteLine (list. Count); - Console.WriteLine (list. capacity); - Console.readkey (); the}
Run:
Code:
1 Static voidMain (string[] args)2 {3 //instantiate a Collection object4ArrayList list =NewArrayList ();5 6List. ADD (1);7List. ADD (2);8List. ADD (3);9List. ADD (4);TenList. ADD (5); OneList. ADD (6); AList. ADD (7); -List. ADD (8); -List. ADD (9); the - Console.WriteLine (list. Count); - Console.WriteLine (list. capacity); - Console.readkey (); +}
Run:
Complete.
ArrayList collection-[Length problem]--c#