Created
January 23, 2013 15:58
-
-
Save Mr-Byte/4608614 to your computer and use it in GitHub Desktop.
C# 5: Works as one would reason.
C# 4 and below: All eight planets are Neptune?! This is why C# 5 is the superior version.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace Test | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var planets = new[] {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"}; | |
var planetPrinters = new List<Action>(); | |
foreach (var planet in planets) | |
{ | |
planetPrinters.Add(() => Console.WriteLine(planet)); | |
} | |
foreach (var printer in planetPrinters) | |
{ | |
printer(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment