An anonymous method that returns a value. : Anonymous delegate « delegate « C# / CSharp Tutorial






using System;  
  
delegate int CountIt(int end);  
  
class MainClass {  
 
  public static void Main() {   
    CountIt count = delegate (int end) { 
      Console.WriteLine("end:"+end);
      return end;
    }; 
 
    int result = count(3); 
    Console.WriteLine("Summation of 3 is " + result); 
 
    result = count(5);  
    Console.WriteLine("Summation of 5 is " + result); 
  } 
}
end:3
Summation of 3 is 3
end:5
Summation of 5 is 5








9.4.Anonymous delegate
9.4.1.Create a delegate by declaration
9.4.2.Anonymous delegate method
9.4.3.An anonymous method.
9.4.4.An anonymous method that takes an argument.
9.4.5.An anonymous method that returns a value.
9.4.6.Demonstrate a captured variable.
9.4.7.Anonymous delegate methods
9.4.8.Anonymous Methods
9.4.9.anonymous method delegate invocation