[Reserved] using the C # ArrayList collection class

During the collection of operations C #, we have a collection of commonly used set of classes for List, List collection is a strongly typed generic collection, in fact, there is a collection classes ArrayList, ArrayList class is a collection of non-generic collection classes, and ArrayList collection class is not strongly typed, any type of data to set new ArrayList can, so during the internal elements of the set time to conversion operations considerable attention, with ArrayList collection rate is slower than the normal array.

To use the ArrayList collection, you first need to introduce the collection namespace: using System.Collections.

To demonstrate the non-strongly typed ArrayList collection, the following examples are given, to set new type Int arrayList, a character string type, and the type of variable custom object set can successfully written.      

 ArrayList arrayList = new ArrayList();
 arrayList.Add(1);
 arrayList.Add("3");
 arrayList.Add(new { Id = 1, Name = "张三" });

From the above point of view the program running results, all normal running, the arrayList set contains three elements, but the data element type 3 is completely different. So if it is determined element type in the data set, it is recommended to avoid the use of ArrayList collection class for storing data, instead of using the generic class List stores data collection more efficient appropriate.

Method ArrayList collection class element is added Add method, signature Add method is: virtual int Add (object value). From the signature we can see any type of data can be added to the ArrayList collection program does not throw exceptions.

 

Note: The text reproduced from personal bloggers station IT technology small fun house , the original link for the use _IT techniques in C # ArrayList class collection of interesting small house .

Bloggers personal technology exchange group: 960 640 092, blogger micro-channel public numbers are as follows:

Guess you like

Origin www.cnblogs.com/xu-yi/p/11246489.html