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.
|