对于经常仅在集合开头插入和删除对象的代码,您会建议使用哪些集合.
这是一些代码来说明我的要求
while (collection.Count != 0)
{
object obj = collection[0];
collection.RemoveAt(0);
...
if (somethingWith(obj))
collection.Insert(0, anotherObj);
...
}
Run Code Online (Sandbox Code Playgroud)
除0以外的位置没有插入或删除.集合未排序.
你会推荐什么?
编辑:
我真的不需要对这个系列做任何想象.该集合用于对应处理的对象进行排队(并在处理期间填充集合).
看来你只想实现一个LIFO容器,所以你可以使用Stack<T>
:
while (stack.Count > 0) {
object obj = stack.Pop();
// ...
if (SomethingWith(obj)) {
stack.Push(anotherObj);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
105 次 |
最近记录: |