mardi 3 mars 2015

Really confusing about captured variable, could anyone help me about following code?


Vote count:

0




What's the difference between counter and index ?


Why the final results between two variables is so huge....?



for (int index = 0; index < 5; index++)
{
int counter = index * 10;
list.Add(delegate
{
Console.WriteLine(counter);
Console.WriteLine(index);
counter++;
});
}

foreach (MethodInvoker invoke in list)
{
invoke();
}

list[0]();
list[0]();
list[0]();

list[1]();
Console.ReadLine();


asked 1 min ago







Really confusing about captured variable, could anyone help me about following code?

Aucun commentaire:

Enregistrer un commentaire