哪个更好?数组、ArrayList 或 List<T>(在性能和速度方面) [英] Which is better? array, ArrayList or List<T> (in terms of performance and speed)
本文介绍了哪个更好?数组、ArrayList 或 List<T>(在性能和速度方面)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要快速处理我的页面.要添加的值的计数将是动态的.
I require a fast speed in processing my page. The count of the values to be added will be dynamic.
以上哪一项是首选?有正当理由的支持.
Which one of the above is preferred? Support with a valid reason.
例如:
string str = "a,b,c"; //Count of the number of elements in str is not fixed
string[] arr = str.Split(',');
或者,
ArrayList al = new ArrayList();
al.Add(str.Split(','));
推荐答案
List
通常应该优先于 ArrayList
- 值类型更快,因为它避免了装箱.
- 强类型元素
如果您希望向调用者公开的列表是不可变的,List
和 ArrayList
都支持:
If you want lists you expose to callers to be immutable, this is supported by both List<T>
and ArrayList
:
List<T>.AsReadOnly()
ArrayList.ReadOnly(ArrayList list);
您的问题是关于在 ArrayList
和 List
之间进行选择,但您的示例显示了一个数组,但两者都不是.
Your question asks about choosing between ArrayList
and List<T>
, but your example shows an array, which is neither.
这篇关于哪个更好?数组、ArrayList 或 List<T>(在性能和速度方面)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文