csharp program lambda Func

Code Example - csharp program lambda Func

                
                        using System;

class Program
{
    static void Main()
    {
        // Part 1: use implicitly-typed lambda expression.
        // ... Assign it to a Func instance.
        Func<int, int> func1 = x => x + 1;
        Console.WriteLine("FUNC1: {0}", func1.Invoke(200));
        
        // Part 2: use lambda expression with statement body.
        Func<int, int> func2 = x => { return x + 1; };
        Console.WriteLine("FUNC2: {0}", func2.Invoke(200));
        
        // Part 3: use formal parameters with expression body.
        Func<int, int> func3 = (int x) => x + 1;
        Console.WriteLine("FUNC3: {0}", func3.Invoke(200));
        
        // Part 4: use parameters with a statement body.
        Func<int, int> func4 = (int x) => { return x + 1; };
        Console.WriteLine("FUNC4: {0}", func4.Invoke(200));
    }
}