← Back to C# Course | Chapter 12: Delegates & Events | Lesson 3 of 6

Lambda Expressions

In this page:

  1. Lambda Expressions

Lambda Expressions

A lambda expression is a compact, inline, unnamed function using the => syntax, useful anywhere a delegate is expected. (x, y) => x + y is equivalent to a full method but written inline. Lambdas are heavily used with LINQ, event handlers, and Func/Action.

Note: A lambda with a single expression body needs no return or braces — the expression's value is returned automatically.

Example: Lambda Expressions

markup
using System;

delegate int Transform(int x);

class Program
{
    static void Main(string[] args)
    {
        Transform square = x => x * x;
        Transform increment = x => x + 1;

        Console.WriteLine(square(5));
        Console.WriteLine(increment(5));
    }
}
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.