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:
Int32[] ints = new int[];
//ints.GetType() {Name = "Int32[]" FullName = "System.Int32[]"} System.Type {System.RuntimeType} Array a = Array.CreateInstance(typeof(System.Int32), );
//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
Array,ArrayList 和 List<T>的选择和性能比较.的更多相关文章
- 类 Array Arraylist List Hashtable Dictionary
总结C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue 我们用的比较多的非泛型集合类主要有 ArrayList类 和 HashT ...
- c#中Array,ArrayList 与List<T>的区别、共性与转换
本文内容来自我写的开源电子书<WoW C#>,现在正在编写中,可以去WOW-Csharp/学习路径总结.md at master · sogeisetsu/WOW-Csharp (gith ...
- Array,ArrayList、List<T>、HashSet<T>、LinkedList<T>与Dictionary<K,V>
Array: 数组在C#中最早出现的.在内存中是连续存储的,所以它的索引速度非常快,而且赋值与修改元素也很简单. 但是数组存在一些不足的地方.在数组的两个数据间插入数据是很麻烦的,而且在声明数组的时候 ...
- 解析C#中[],List,Array,ArrayList的区别及应用
[] 是针对特定类型.固定长度的. List 是针对特定类型.任意长度的. Array 是针对任意类型.固定长度的. ArrayList 是针对任意类型.任意长度的. Array 和 ArrayLis ...
- .net中的Array,ArrayList和List
Array:任意类型,定长 ArrayList:任意类型,不定长 List:特定类型,不定长 Array和ArrayList是通过存储object类型实现可以存储任意类型数据,使用时需要拆箱和装箱
- [置顶] Array ArrayList LinkList的区别剖析
这是一个面试中我们经常被问到的问题 Array.ArrayList.LinkList之间的区别:Array.ArrayList.LinkList均属于泛型的范畴,都用来存放元素,主要区别是Array是 ...
- C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)
int [] numbers = new int[5]; // 长度为5,元素类型为 int.string[,] names = new string[5,4]; // 5*4 的二维数组byte[] ...
- Array,ArrayList,泛型List比较
在C#中数组Array,ArrayList,泛型List都能够存储一组对象,但是在开发中根本不知道用哪个性能最高,下面我们慢慢分析分析. 一.数组Array 数组是一个存储相同类型元素的固定大小的顺序 ...
- C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)
int [] numbers = new int[5]; // 长度为5,元素类型为 int. string[,] names = new string[5,4]; // 5*4 的二维数组 byte ...
随机推荐
- 支付宝openssl漏洞肆虐 互联网巨头称目前已修复
支付宝openssl漏洞肆虐 互联网巨头称目前已修复 金山毒霸安全专家李铁军表示,这个漏洞使黑客可以远程读取https服务器的随机64KB内存,“只要这个黑客有耐心多捕获多分析那些64KB的数据,用户 ...
- codeforces C. Painting Fence
http://codeforces.com/contest/448/problem/C 题意:给你n宽度为1,高度为ai的木板,然后用刷子刷颜色,可以横着刷.刷着刷,问最少刷多少次可以全部刷上颜色. ...
- 查看SQLServer各种缓存的情况
查看页面缓存: SELECT * FROM sys.dm_os_buffer_descriptors 清除页面缓存: CHECKPOINTDBCC DROPCLEANBUFFERS 查看执行计划缓存: ...
- I2C总线之(二)---时序
一.协议 1.空闲状态 I2C总线总线的SDA和SCL两条信号线同时处于高电平时,规定为总线的空闲状态.此时各个器件的输出级场效应管均处在截止状态,即释放总线,由两条信号线各自的上拉电阻把电平拉高. ...
- Tomcat7+Redis存储Session(转)
PS:截止到2015-05-12前是不支持Tomcat8的,详情见官网:https://github.com/jcoleman/tomcat-redis-session-manager 前提:你已经部 ...
- hadoop2.0 eclipse 源码编译
在eclipse下编译hadoop2.0源码 http://www.cnblogs.com/meibenjin/archive/2013/07/05/3172889.html hadoop cdh4编 ...
- HDU-4920 Matrix multiplication
矩阵相乘,采用一行的去访问,比采用一列访问时间更短,根据数组是一行去储存的.神奇小代码. Matrix multiplication Time Limit: 4000/2000 MS (Java/Ot ...
- 数据库的存储引擎和SQL语言
数据库的存储引擎就是管理数据存储的东西,它完成下面的工作: 1)存储机制 2)索引方式 3)锁 4)等等 SQL语言:-----关系型数据库所使用的数据管理语言 1)数据定义语言(DDL):DROP. ...
- Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1959 Solved: 1229[Submit][ ...
- ERROR: The node /hbase is not in ZooKeeper. It should have been written by the master. Check the value configured in 'zookeeper.znode.parent'. There could be a mismatch with the one configured in the
hbase shell下list命令出错. [hadoop@djt002 hbase]$ hbase shell 2016-07-20 19:37:12,522 INFO [main] Confi ...