最佳字符串容器:StringCollection、Collection<string>、List<string>、ArrayList、..? [英] Best string container: StringCollection, Collection&lt;string&gt;, List&lt;string&gt;, ArrayList, ..?

查看:45
本文介绍了最佳字符串容器:StringCollection、Collection<string>、List<string>、ArrayList、..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最合适的容器,仅用于保存在具有非预定上限的数组中的字符串,其长度在创建时是未知的.

What is the most suitable container just for strings holding in some array with non-predetermined upper boundary, which length is unknown on it's creation.

对于简单的代码,例如:

For simple code like:

var list = new SomeContainer(); // size is unknown
for()/foreach()/do()/while() // any loop
{
  list.Add(string);
}

它是 StringCollection 作为字符串的优化集合,还是只是 CollectionListArrayList ?它们有什么不同?

Is it StringCollection as optimized Collection for string, or just Collection<string> or List<string> or ArrayList ? What is the different between them?

推荐答案

对于你所需要的,List 可能是最通用的.StringCollection 在 1.1 中很方便,当(没有泛型)您需要特定的类用于类型化集合时.Collection<string> 如果您想将其子类化以提供验证等,则非常方便.

For what you need, List<string> is probably the most versatile. StringCollection was handy in 1.1, when (without generics) you needed specific classes for typed collections. Collection<string> is handy if you want to subclass it to provide validation etc.

无论如何,在 3.5 中,LINQ 将为它们提供许多额外的方法 - 但没有 LINQ,List<T> 具有更多功能(Find排序等)

Either way, in 3.5, LINQ will provide lots of additional methods for them - but without LINQ, List<T> has more features (Find, Sort, etc)

这篇关于最佳字符串容器:StringCollection、Collection<string>、List<string>、ArrayList、..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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