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、..?


- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01