【发布时间】:2015-11-08 07:06:48
【问题描述】:
我想知道 Array、ArrayList 和 List 之间的确切区别是什么(因为它们都有相似的概念)以及在哪里你会使用其中一个。
示例:
数组
对于 Array,我们只能添加为本示例声明为 int 的类型。
int[] Array = new Int[5]; //Instansiation of an array
for(int i = 0; i < Array.Length; i++)
{
Array[i] = i + 5; //Add values to each array index
}
数组列表
我们可以像 Array
ArrayList arrayList = new ArrayList();
arrayList.Add(6);
arrayList.Add(8);
列表
同样,我们可以像在 Array
List<int> list = new List<int>();
list.Add(6);
List.Add(8);
我知道在 List 中你可以有泛型类型 所以你可以传入任何你不能在 Array 中做的类型但我的确切问题是:
- 你会在哪里使用一个而不是另一个?
- 这三者之间在功能方面的确切区别?
【问题讨论】:
-
stackoverflow.com/questions/2309694/… 中涵盖的 ArrayList 与 List(用作副本),stackoverflow.com/questions/412813/… 中涵盖的 Array 与 ArrayList。如果这 2 个问题没有涵盖您的所有问题,请创建新问题,明确说明您要查找的新信息。确保首先搜索现有问题 - bing.com/search?q=C%23+array+vs+arraylist
-
哦,是的,很抱歉。学习这个网站的绳索。谢谢你以后会多看看。