I translated this code(it has bad side effect that it just capture the outer variable):
foreach (TaskPluginInfo tpi in Values)
{
GenerateMenu(menuStrip, tpi.MenuTree, tpi.MenuText, delegate { tpi.ShowTask() });
}
To this code(because the above is not working):
foreach (TaskPluginInfo tpi in Values)
{
// must capture the variable
var x = tpi;
GenerateMenu(menuStrip, tpi.MenuTree, tpi.MenuText, delegate { x.ShowTask(); });
}
What's the correct terminology for that work-around on that little known side effect? For now, I commented "must capture the variable." Is the word capture, the correct terminology?