Skip to content

Instantly share code, notes, and snippets.

@pragmaticlogic
Created December 6, 2013 22:24
Show Gist options
  • Save pragmaticlogic/7833186 to your computer and use it in GitHub Desktop.
Save pragmaticlogic/7833186 to your computer and use it in GitHub Desktop.
class Program
{
private static Func<int>[] GetFunc()
{
int SIZE = 5;
Func<int>[] func = new Func<int>[SIZE];
for (int i = 0; i < SIZE; i++)
{
int j = i;
func[i] = () => j;
}
return func;
}
public static void Main(string[] args)
{
var funcs = Program.GetFunc();
foreach (Func<int> func in funcs)
{
Console.Out.WriteLine(func());
}
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment