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 ...
随机推荐
- QQ 群也能接收告警啦!团队沟通力 Up Up!
截止到昨天,你已经可以通过 OneAlert 的「排班」和「分派」功能,来对告警进行有序地分发,解决团队协作效率低的问题了.然而 OneAlert 觉得自己还可以更进一步,把团队沟通困难的问题也解决掉 ...
- LED七彩变色灯的制作
LED变色灯是一种新型灯泡.它的外形与一般乳白色白炽灯泡相同,但点亮后会自动按一定的时间间隔变色.循环地发出青.黄.绿.紫.蓝.红.白色光.它适用于家庭生日派对.节日聚会.过节过年,给节日添加欢乐气氛 ...
- 【HDOJ】3221 Brute-force Algorithm
归来吧很好推导.T(n) = a^f(n-1)*b^f(n)%p.主要难点在于求mod和fibo.引用如下公式A^B%C = A^(B%phi(C) + phi(C))%C, 满足B>=phi( ...
- Google Map API 学习四
- Windows玩转Docker(一):安装
Docker官网地址: http://www.docker.com/ 本文参照site: https://docs.docker.com/windows/ Docker 项目的目标是实现轻量级的操作系 ...
- http 协议的过程
当你输入某个网址的时候发生了什么? 首先:你该知道 a.http协议是应用层协议,他是浏览器像服务器请求网页,服务器返回网页的过程,他是基于tcp协议的. 1.假设随便输入输入域名 http://ww ...
- C# 使用Nlog记录日志到数据库 使用LogEventInfo类获取,命名空间名称、类名、方法名
原文地址:http://dotnet.9sssd.com/csbase/art/793 [摘要]Nlog是一个很不错的.NET日志记录组件,它可以将日志输出到控件台,保存到文本,也可以很方便的记录到数 ...
- 简单tableView的使用
UITableView是一个用于显示列表的视图,可以作为子视图镶嵌在主视图上,可以滑动,选取各种参数 定义: @interface ViewController : UIViewController& ...
- hdu 2546 饭卡(DP)
很久以前做过这道题,晚上睡不着,看见nyist加了一个DP的比赛,就进来打个酱油. 这道题的点睛之笔是将最大值记录下来,然后将其值改为0.之后就是普通的背包了. #include<stdio.h ...
- Swing的设计是MVC的典范
无论你的项目是否用到了Swing技术,我都要说,Swing是一个设计优秀的Java包,它充满了大师的智慧.假设你学了Java却连一个Button还不会写,就象你学习Visual Basic却不会用Bu ...