Array,ArrayList 和 List<T>的选择和性能比较.
Array Class
- Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime
- In my opinion,int32[] is an example of Array,so is double[] and so on.for instance:
1 Int32[] ints = new int[3]; 2 //ints.GetType() {Name = "Int32[]" FullName = "System.Int32[]"} System.Type {System.RuntimeType} 3 4 Array a = Array.CreateInstance(typeof(System.Int32), 3); 5 //a.GetType() {Name = "Int32[]" FullName = "System.Int32[]"} System.Type {System.RuntimeType}
When to use: Array is strongly type,and is work well as parameter,if the the collection is fixed,we should should use Array instead of ArrayList.
ArrayList Class
ArrlayList isn't strongly type,every Insertion or Retrial will need a cast to get back to your original type. If you need a method to take a list of a specific type, ArrayLists fall short because you could pass in an ArrayList containing any type,that is,we could contains Object,Int32,Double in the same ArrayList. ArrayLists use a dynamically expanding array internally, so there is also a hit to expand the size of the internal array when it hits its capacity.
An ArrayList doesn't use a LinkedList as the internal data structure! It uses a vector which is an array that is dynamically resized on add/insert/delete operations.
Actually,most of the time,the operations relevant to Array,such as Copy,IndexOf,Clear and so on.
List<T>
Most of the time,we use List<T> and it contains all the advantages of Array and ArrayLists. It is strongly typed and it supports a variable length of items.
Ref:
http://msdn.microsoft.com/en-us//library/system.array(v=vs.110).aspx in msdn
http://stackoverflow.com/questions/412813/when-to-use-arraylist-over-array-in-c from StackOverflow