有没有办法使用直接循环迭代ValueCollection?(不是foreach)
例如
Dictionary<string, List<long>>.ValueCollection somevalues = somecollection.Value.Values;
for(int i = 0; i< somevalues.Count; i++)
{
//now what?
}
Run Code Online (Sandbox Code Playgroud)
不 - 没有索引器或任何类似的东西ValueCollection.我想你可以使用:
for (int i = 0; i < someValues.Count; i++)
{
var item = someValues.ElementAt(i);
...
}
Run Code Online (Sandbox Code Playgroud)
但这会像狗一样表现:)(只是迭代将是O(n ^ 2),因为它就像Schlemiel the Painter.)
你为什么要这样做?如果你想要带有元素的项目,只需保留一个计数器或使用在索引和项目中传递的重载Select.
| 归档时间: |
|
| 查看次数: |
2537 次 |
| 最近记录: |