I translated this code (it has a bad side effect that it just captures an external variable):
foreach (TaskPluginInfo tpi in Values)
{
GenerateMenu(menuStrip, tpi.MenuTree, tpi.MenuText, delegate { tpi.ShowTask() });
}
To this code (because above does not work):
foreach (TaskPluginInfo tpi in Values)
{
var x = tpi;
GenerateMenu(menuStrip, tpi.MenuTree, tpi.MenuText, delegate { x.ShowTask(); });
}
What is the correct terminology for this work around this little-known side effect? At the moment, I commented that "must capture the variable." Is capturing the right terminology?
source
share