I have a Dictionary<string,string> and I iterate over its KeyValuePairs. But my issue is that I need to stop the iteration at some point and continue the iteration from the same position. My code is as follows.
for(i = 0; i<5; i++)
{
foreach(var pair in dictionary) /* continue from iterators last position */
{
/* do something */
if(consdition) break;
}
}
The code is not very clear but I hope my what I’m trying to do is. What do I do?
You could abandon
foreachand work on theIEnumerator<T>directly.But you might consider refactoring the code so that
foreachis the outer loop. That’s probably easier and cleaner.