如何以及何时放弃在C#中使用数组? [英] How and when to abandon the use of arrays in C#?

查看:120
本文介绍了如何以及何时放弃在C#中使用数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是被告知,添加元素为数组情况是这样的:

I've always been told that adding an element to an array happens like this:

数组的空复制+ 1element是
  创建,然后从该数据
  原数组复制到它,然后
  为新的元素的新数据是
  然后装

An empty copy of the array+1element is created and then the data from the original array is copied into it then the new data for the new element is then loaded

如果这是真的话,那么使用需要诸多因素的活动方案中的数组是禁忌由于内存和CPU使用率,是否正确?

If this is true, then using an array within a scenario that requires a lot of element activity is contra-indicated due to memory and CPU utilization, correct?

如果是这样的话,你不应该尽量避免使用数组尽可能当你将增加很多的元素?如果您使用iStringMap呢?如果是这样,如果你需要两个以上的尺寸和需要补充大量的元素添加会发生什么。难道你只需要对性能的影响还是有别的东西,应该用?

If that is the case, shouldn't you try to avoid using an array as much as possible when you will be adding a lot of elements? Should you use iStringMap instead? If so, what happens if you need more than two dimensions AND need to add a lot of element additions. Do you just take the performance hit or is there something else that should be used?

推荐答案

看泛型List< T>作为阵列的替代品。它们支持大多数的同样的事情做阵列,包括如果你想分配初始存储容量。

Look at the generic List<T> as a replacement for arrays. They support most of the same things arrays do, including allocating an initial storage size if you want.

这篇关于如何以及何时放弃在C#中使用数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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