Skip to content

Instantly share code, notes, and snippets.

Created November 22, 2010 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/709647 to your computer and use it in GitHub Desktop.
Save anonymous/709647 to your computer and use it in GitHub Desktop.
C#: anonymous lambda in a loop
static void LoopWithAnoymousLambda()
{
List<Action> methodList = new List<Action>();
for (int i = 0; i < 5; i++)
{
methodList.Add(
() =>
Console.WriteLine(i)
);
}
foreach (Action method in methodList)
{
method();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment