Is there a way to iterate ValueCollection using straight for loop? (not foreach)
e.g.
Dictionary<string, List<long>>.ValueCollection somevalues = somecollection.Value.Values;
for(int i = 0; i< somevalues.Count; i++)
{
//now what?
}
No - there's no indexer or anything similar for ValueCollection. I suppose you could use:
for (int i = 0; i < someValues.Count; i++)
{
var item = someValues.ElementAt(i);
...
}
but that would perform like a dog :) (Just iteration would be O(n^2), as it would be like Schlemiel the Painter.)
Why do you want to do this? If you want items with elements, just keep a counter or use the overload of Select that passes in the index as well as the item.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With