在阵VS数组列表显著差异? [英] Significant differences in Array vs Array List?

查看:100
本文介绍了在阵VS数组列表显著差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  当在C#中使用ArrayList比数组[]?

从内存或处理器成本的角度来看,确实似乎有一个数组和ArrayList对象之间有显著区别?

From the perspective of memory or processor costs, does there appear to be a significant difference between an array and an arrayList object?

推荐答案

阵列(系统命名空间)是一种数据类型,可以通过调用索引使用。运行过程中,不能真正改变数组的大小,除非您使用复制阵列和摆脱旧的方法。

Array (A System namespace) is a datatype, that can be used by calling indexes. during runtime, one cannot really change the size of the array, unless you use the method of copying the array and getting rid of the old one.

在.NET,Visual Studio的利用一类特殊的存储数据。正因为如此,性能其实是相当快的。这也是因为在数组,需要指定的大小,因此,该数据被存储一前一后。

In .NET, the Visual Studio makes use of a special class to store the data. Because of this, the performance is actually quite fast. This is also because in an array, you need to specify the size and thus, the data is stored one after the other.

例如:

int[] myNumbers= new int[5];
myNumbers[0] = 16;

的ArrayList(System.Collections命名空间)是一种数据类型的集合。为了填补一个ArrayList,可以使用。新增方法。的ArrayList是在这个意义上非常动态的,当你添加和/或删除其中的项目,未来在性能上保持不变。

ArrayList (System.Collections namespace) is a datatype collection. In order to fill an ArrayList, one can use the .Add method. ArrayLists are very dynamic in the sense that when you add and/or remove items from it, the performace stays the same.

一个ArrayList的内部结构是一个数组。

The internal structure of an ArrayList is an array.

例如:

ArrayList myArray = new ArrayList();
myArray.Add("Steph");
string str = myArray[0];

在大多数情况下,我们倾向于选择数组列表,而不是数组,因为我们不知道它会如何大转出。阵列是理想的,当你知道你要多少个项目就摆在这。只要有可能,建议使用数组,因为这大大提高了性能。

Most of the time, we tend to choose array lists rather than arrays since we have no idea how big it is going to turn out. Arrays are ideal when you know how many items you are going to put in it. Whenever possible, it is recommended to use arrays as this drastically improves the performance.

数组是同质的数据序列,而ArrayList是异构数据的序列。这就是为什么我们要在每一个的ArrayList类型转换数据。

Array are sequence of homogeneous data while ArrayList is sequence of heterogenous data. That's why we have to typecast every data in ArrayLists.

数组是多方面的,但ArrayList中始终是一维的。

Arrays are multidimensional but ArrayList is always single-dimensional.

数组是强类型,并且参数正常工作。如果你知道你收藏的长度,它是固定的,你应该使用数组。

Arrays are strongly typed, and work well as parameters. If you know the length of your collection and it is fixed, you should use an array.

的ArrayList不强类型,每插入或再审将需要一个投地回到你原来的类型。如果你需要采取特定类型的列表的方法,的ArrayList功亏一篑,因为你可以在包含任何类型的ArrayList通过。的ArrayList使用动态扩展阵列内部,所以也有命中,扩大内部数组的大小,当它击中的能力。

ArrayLists are not strongly typed, 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. 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.

这篇关于在阵VS数组列表显著差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆