Scribbles on Software Engineering
var values = new List() { 100, 110, 120 }; var funcs = new List<func<int>>(); foreach (var v in values) funcs.Add(() => v); foreach (var f in funcs) Console.WriteLine(f());
I will answer with a question : Will the following code have the same effect?foreach (var v in values){ int i = v; funcs.Add(() => i);}
Perfect ;) It will not have the same output indeed!
That's my boy Nikos... ;)
I will answer with a question :
ReplyDeleteWill the following code have the same effect?
foreach (var v in values)
{
int i = v;
funcs.Add(() => i);
}
Perfect ;) It will not have the same output indeed!
ReplyDeleteThat's my boy Nikos... ;)
ReplyDelete