lambda

In this chapter you will learn:

  1. What is lambda expressions

lambda expressions

lambda is an anonymous delegate instance. Suppose we have a delegate:

delegate int Calculate(int i);

We can create an lambda expression as follows:

Calculate c = x => x+1;

x is the parameter and x+1 is the method body.

The following code puts everything together to show how to use lamda expression.

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

delegate int Calculate(int i);


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

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

The output:

Next chapter...

What you will learn in the next chapter:

  1. Syntax of 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