Created
December 10, 2012 06:36
-
-
Save fresky/4248836 to your computer and use it in GitHub Desktop.
Watch out the ToString() and ToString in the delegate.
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
public class Program | |
{ | |
public static int StaticInt = 0; | |
static Func<string> delegate1 = new Func<string>(StaticInt.ToString); | |
static Func<string> delegate2 = new Func<string>(() => StaticInt.ToString()); | |
static void Main(string[] args) | |
{ | |
StaticInt = 10; | |
Console.WriteLine("StaticInt = {0}, StaticInt.ToString: {1}", StaticInt, delegate1()); | |
Console.WriteLine("StaticInt = {0}, () => StaticInt.ToString(): {1}", StaticInt, delegate2()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment