When I add to array
of Actions
with a for loop
a delegate
the I is updated across the array. How to prevent that from happening?
I have tried assigning the "I" to an integer before adding that works.
Action[] actions = new Action[100];
for (int i = 0;i< actions.Length; i++)
{
actions[i] = () => Console.WriteLine("Hello"+ i);
}
"I" in each Action in Action[]
is 100;
Why is that?