Best string container: StringCollection, Collectionlt;stringgt;, Listlt;stringgt;, ArrayList, ..?(最佳字符串容器:StringCollection、Collectionstring、Liststring、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
作为字符串的优化集合,还是只是 Collection
或 List
或 ArrayList代码> ?它们有什么不同?
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、..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:最佳字符串容器:StringCollection、Collection<string>、List<string>、ArrayList、..?


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01