哪个更好?阵列,ArrayList中或列表&LT; T&GT; (在性能和速度方面) [英] Which is better? array, ArrayList or List<T> (in terms of performance and speed)
问题描述
我需要处理我的网页速度快。要添加的值的计数将是动态
这pferred上面是$ P $之一吗?支持具有正当的理由。
编辑:对于如:
字符串str =A,B,C; // str中元素的数量的计数是不固定
字符串[] = ARR str.Split('');
或
ArrayList的人=新的ArrayList();
al.Add(str.Split(,));
列表&LT; T&GT;
一般应pferred超过 $ P $的ArrayList
- 更快的值类型,因为它避免了拳击。
- 强类型元素
如果你想你暴露给调用者名单是不变的,这是由双方支持列表&LT; T&GT;
和的ArrayList
:
列表&LT; T&GT; .AsReadOnly()
ArrayList.ReadOnly(ArrayList的列表);
您的问题询问有关的ArrayList
和列表℃之间选择; T&GT;
,但你的例子显示了一个数组,两者都不是。
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.
Edit: For eg:
string str = "a,b,c"; //Count of the number of elements in str is not fixed
string[] arr = str.Split(',');
or,
ArrayList al = new ArrayList();
al.Add(str.Split(','));
List<T>
should generally be preferred over ArrayList
- faster for value types as it avoids boxing.
- strongly typed elements
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);
Your question asks about choosing between ArrayList
and List<T>
, but your example shows an array, which is neither.
这篇关于哪个更好?阵列,ArrayList中或列表&LT; T&GT; (在性能和速度方面)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!