Skip to content

Instantly share code, notes, and snippets.

@plioi
Created March 7, 2012 00:34
Show Gist options
  • Save plioi/1990116 to your computer and use it in GitHub Desktop.
Save plioi/1990116 to your computer and use it in GitHub Desktop.
var delayedGreetings = new List<Func<string>>();
{
using (var e = ((IEnumerable<string>)new[] { "Larry", "Moe", "Curly" }).GetEnumerator())
{
string name;
while (e.MoveNext())
{
name = e.Current;
delayedGreetings.Add(() => "Hello, " + name + "!");
}
}
}
//Some time later...
foreach (var greeting in delayedGreetings)
Console.WriteLine(greeting());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment