I have a nested loop “structure” in my code. Sometimes, I get the below message.
Collection was modified; enumeration operation may not execute.
I have a collection I am looping through, like below. Coll is a List<string>
foreach (string[] s1 in obj.Coll
{
foreach (string s in s1) { }
}
For each string in the array, I need to work with it (read as read the value, not write).
All I do with it is get directories (this value is a path) and split this string into an array.
How can this be resolved?
You can try:
That will take a copy before starting iteration!