lambda syntax

In this chapter you will learn:

  1. Syntax of lambda

Syntax of lambda

Lambda has the following syntax.

(parameters) => expression-or-statement-block

The parameters are defined by the delegate and the return type of expression-or-statement-block must be consistant with delegate return type.

We can use return type in lambda expression.

using System;//j  a v a 2  s. com

delegate int Calculate(int i);

class Program
{
    public static void Main()
    {
        Calculate c = x => {return x + 1;}

        Console.WriteLine(c(1));
    }
}

The result:

Next chapter...

What you will learn in the next chapter:

  1. How to use Func, Action and lambda
Home » C# Tutorial » delegate, lambda, event
delegate
Multicast delegate
delegate variables
delegate parameters
Generic delegate
delegate return
Func and Action
delegate new
chained delegate
Anonymous delegate
delegate array
Return a delegate
delegate as parameter
Event
event multicast
static event
EventHandler
Event pattern
lambda
lambda syntax
Func, Action and lambda
lambda with outer function
lambda iteration variables