Array,ArrayList 和 List<T>的选择和性能比较.
2014-01-07 10:53
656 查看
Array Class
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtimeIn my opinion,int32[] is an example of Array,so is double[] and so on.for instance:
Int32[] ints = new int[3]; //ints.GetType() {Name = "Int32[]" FullName = "System.Int32[]"} System.Type {System.RuntimeType} Array a = Array.CreateInstance(typeof(System.Int32), 3); //a.GetType() {Name = "Int32[]" FullName = "System.Int32[]"} System.Type {System.RuntimeType}
When to use:[b] Array is strongly type,and is work well as parameter,if the the collection is fixed,we should should use Array instead of ArrayList.[/b]
ArrayList Class
[b] 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.[/b][b] 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.[/b]
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
相关文章推荐
- ArrayList Array List<T>性能比较
- C# List<>与Array性能比较
- List<T> 与ArrayList 性能比较
- C# List<>与Array性能比较
- C# List<>与Array性能比较
- C# List<>与Array性能比较
- ArrayList的使用和List<T>的比较
- C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)
- ArrayList的使用和List<T>的比较
- 数组、LIst<> 、 ArrayList的性能对比
- 数组排序方法的性能比较(2):Array.Sort<T>实现分析
- 泛型集合List<T>和非泛型集合ArrayList性能比较
- Array,ArrayList,List<>,Dictionary和HashTable
- 粗谈C#里 dictionary,HashTable,List<T>,Array 的性能优缺和实现原理。
- ArrayList和List<T>的性能区别
- ArrayList List<T> T[] Array
- List<T>在搜索和排序时采用不同方法的性能比较
- 数组、ArrayList、List<T>区别和选择
- .net集合类的研究--Array,ArrayList,List<T>
- c#初学-泛型ArrayList的使用和List<T>的比较