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、..?
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
