最佳字符串容器:StringCollection、Collection<string>、List<string>、ArrayList、..?

Best string container: StringCollection, Collectionlt;stringgt;, Listlt;stringgt;, ArrayList, ..?(最佳字符串容器:StringCollection、Collectionstring、Liststring、ArrayList、..?)
本文介绍了最佳字符串容器: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、..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)