Anonymous methods can refer to local variables of the containing function and class members within the scope of the method definition : delegate anonymous : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » delegate anonymous »

 

Anonymous methods can refer to local variables of the containing function and class members within the scope of the method definition








    
 

using System;

public delegate void DelegateClass(out int arg);

public class Starter {

    public static void Main() {

        DelegateClass del = MethodA();
        int var;
        del(out var);

        Console.WriteLine(var);
    }

    public static DelegateClass MethodA() {
        int local = 0;
        return delegate(out int arg) {
            arg = ++local;
        };
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» delegate anonymous