Publicité

Andy On Closures

25 Nov 2007
Publicité

Contenu connexe

Publicité
Publicité

Andy On Closures

  1. Andy Bulka Technical Director Austhink Software www.austhink.com
  2. Example – C# class Program { delegate void Action(); static Action GetAction() { int x = 0; Action a = delegate { Console.WriteLine(x); }; x = 1; return a; } static void Main(string[] args) { Action a = GetAction(); a(); } }
  3. Example – C# class Program { delegate void SomeDelegate(); public static void InvokeMethod () { SomeDelegate del = delegate() { Console.WriteLine("Hello2"); }; del(); } } class Program { delegate void SomeDelegate(); public static void InvokeMethod () { SomeDelegate del = new SomeDelegate( SomeMethod ); del(); } static void SomeMethod() { Console.WriteLine("Hello"); } } static void Main(string[] args) { InvokeMethod (); }
Publicité