Hi All,
This question is asked many a time in this forum. I know solution for the problem. But I am curious to know why "Enumeration operation can not execute when a collection is modified"
List<string> list = new List<string>();
list.Add("a");
list.Add("b");
int[] array = new int[6] { 1, 2, 3, 4, 5, 5 };
HashSet<int> hashSet = new HashSet<int>();
int i = 0;
foreach (string s in list)
{
list[i] = "test";
i++;
}
But when I change list to list.toarray
It works.
I am new to C#, sorry if the question does not make any sense.
Thanks,