C# Lambda Expression

Introduction

Lambda Expression concept was introduced in C# 3.0 . Lambda expression can be assumed as a more concise syntax of anonymous method. Anonymous methods can be written with C Sharp Lamda Expression. At the time of Compilation lambda expression converted in anonymous method , It is a Lambda expression conversion rule. On Left side of Lambda operator “=>” represent the argument to the method and on right side method body.

Syntax
(parameters) => expression or _statement block

Types

There are basically 2 types of Lambda expression

1. Statement Lambda: It has a statement block on the right side of lambda operator “=>”

for example i=> (return i*I ;);

2. Expression Lambda: It has only an expression k=>k*k; // here k*k is expression

Features

  1. Lambda expression does not have type. In CLR there is no concept of Lambda.
  2. Jump statements are not allowed within anonymous method/lambda expression.
  3. Lambda expression generally used with the Function and action Delegate.
  4. Variables which are defined within a lambda expression , has the scope only within the Lambda expression body.
Ebook Download
View all
FileInfo in C#
Read by 9.7k people
Download Now!
Learn
View all