Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    Five equivalent functions - from anonymous method expressions to lambda expressions.Lecture 6 - slide 10 : 20
Program 1
using System;
using System.Collections.Generic;

class Program{

  public delegate double NumericFunction(double d);   

  public static void Main(){

    NumericFunction[] equivalentFunctions = 
       new NumericFunction[]{
         delegate (double d){return d*d*d;},    
         (double d) => {return d*d*d;},         
         (double d) => d*d*d,                   
         (d) => d*d*d,                          
         d => d*d*d                             
      };

    foreach(NumericFunction nf in equivalentFunctions)
       Console.WriteLine("NumericFunction({0}) = {1}", 5, nf(5));
  }

}
 
 
 
 
 
 
 
 
 
 
 
A delegate anonymous method.
A lambda expression that uses return.
A lambda expression with implicit return.
A lambda expression with inference of the type of d.
As short as it gets.