First, non-generic sets and generic collections
Non-generic collection: Array, ArrayList, HashTable, Queue, Statck, SortedList
Generic collection: List, Dictionary, Queue, Stack, SortedList
Ii. Common collection Classes
Array, ArrayList, List
(a) Array:
That is, a common array form, fixed size, and a namespace of system
(b) ArrayList:
The namespace is system.collection, which is a complex version of the array. The ArrayList class provides some of the features that are available in most collections classes, but are not available in the Array class.
Variable length, using the Add () method can be used to dynamically delete the ArrayList collection operation.
The ArrayList element type belongs to the object type, because it does not point out the exact type, so when the data is stored or retrieved, the operation of boxing and unpacking will occur, causing the system to consume.
Use:
ArrayList arrayList1 = new ArrayList ();
Arraylist1.add ("a");
Arraylist1.add (1);
Arraylist1.add ("B");
Response.Write (Arraylist1[1]);
ArrayList-owned methods:
1:add () Adds an element to the array,
2:remove () to delete an element in an array
3:removeat (int i) delete an element with an index value of I in an array
4:reverse () Reverses the elements of an array
5:sort () The elements of an array in order from small to large
6:clone () copy an array
(c) List
The so-called generic collection, the namespace isSystem.Collections.Generic;使用方法与ArrayList类似,只是给出了具体的类型T,使用时无装箱拆箱操作,节约了内存
Usage:
list<string> names = new list<string> ();
Names. ADD ("Qiao");
Names. Add ("Yin");
Names. ADD ("Wasp");
Traverse List
foreach (string name in Names)
{
Console.WriteLine (name);
}
Inserting an element into the list
Names. Insert (2, "Zhang Sanfeng");
Removing the specified element
Names. Remove ("Wasp");
Comparison of common collection classes in C #