Skip to content

Instantly share code, notes, and snippets.

@fresky
Created December 10, 2012 06:36
Show Gist options
  • Save fresky/4248836 to your computer and use it in GitHub Desktop.
Save fresky/4248836 to your computer and use it in GitHub Desktop.
Watch out the ToString() and ToString in the delegate.
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