哪个更好?阵列,ArrayList中或列表< T> (在性能和速度方面) [英] Which is better? array, ArrayList or List<T> (in terms of performance and speed)

查看:186
本文介绍了哪个更好?阵列,ArrayList中或列表< T> (在性能和速度方面)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要处理我的网页速度快。要添加的值的计数将是动态

这pferred上面是$ P $之一吗?支持具有正当的理由。

编辑:对于如:

 字符串str =A,B,C; // str中元素的数量的计数是不固定
字符串[] = ARR str.Split('');

  ArrayList的人=新的ArrayList();
al.Add(str.Split(,));


解决方案

列表< T> 一般应pferred超过 $ P $的ArrayList


  • 更快的值类型,因为它避免了拳击。

  • 强类型元素

如果你想你暴露给调用者名单是不变的,这是由双方支持列表< T> 的ArrayList

 列表< T> .AsReadOnly()
ArrayList.ReadOnly(ArrayList的列表);

您的问题询问有关的ArrayList 列表℃之间选择; 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.

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屋!

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