static void Main()
{
// First build a list of actions
List<Action> actions = new List<Action>();
for (int counter = 0; counter < 10; counter++)
{
actions.Add(() => Console.WriteLine(counter));
}
// Then execute them
foreach (Action action in actions)
{
action();
}
}
http://csharpindepth.com/Articles/Chapter5/Closures.aspx
请注意这一行:
actions.Add( ())括号内的()是什么意思?
相似问题