. Net Video Learning 2nd-quarter C # Object-oriented
Object-oriented ArrayList
Array: type single (unless it is a parent array, the subclass object is an element--- attention to the element or is considered to be the parent class object!) ), fixed length
int New int [ten];
Collection: Namespace System.Collections
New ArrayList ();
Add data to the collection
List. ADD (1);
For the same set, you can add any type of data inside. (Note that the input parameter of the Add () method is the object class, which is the base class for all types)
ArrayList does not have the length property, but it has the Count property, essentially the same.
int a =list. Count;
From the top you can see that the set is at least two advantages than the array, the first is not to consider whether the element type is consistent, the second is not to consider the length problem.
Again, ADD () puts the elements in the collection as objects of the object class, not the object of the class of the element itself!!
(The data is very cool, with the data very hard to force ———— to convert data type)
Another way to add data (collection types) to the collection: AddRange (), which is already known as the collection type when added, note that the entire array is not considered an element!
List. ADD (1);
Int[] A = new int[]{1,2,3}list. AddRange (a);
Empty: List. Clear ();
Clears an item: list. Remove (X); Delete the first x in the list of a collection
Clear an item by subscript: list. RemoveAt (int a);
Delete an item in a subscript range: list. RemoveRange (int A, int b); A is the subscript for the first item removed, and B is the length of the Purge range
Set element order reversal: list. Reverse (); Note that if the collection type is placed in the collection by AddRange () as an element, the collection reverse the data inside the element will be reversed
Insert element: List. Insert (int a, X); Insert data x at subscript a
Insert collection: List. Insertrange (int a, L);
Determine if there is an element: list. Contains (X); Add elements to the collection with Add ()
Count property: Current number of elements
Capcity Property: The number of elements that can be accommodated
When Count is greater than capcity, one more space is applied to the memory (opening new space twice as much as the original space, copying data, destroying the original space)
Therefore, be careful not to use list when adding elements to an empty collection. Count is judged as a loop, because the new Arraylist,count and capcity are all 0.
. NET Learning 2nd season C # object-oriented ArrayList