---
title: "Lambda Expression in c#"  
description: "In this blog, I’m explaining about the lambda expression in C#. Lambda expressions are anonymous methods, aimed at mainly addressing the \"vertical pro"  
author: "priyanka kushwaha"  
published: 2015-01-20  
updated: 2015-01-20  
canonical: https://www.mindstick.com/blog/723/lambda-expression-in-c-sharp  
category: ".net"  
tags: ["c#", ".net"]  
reading_time: 1 minute  

---

# Lambda Expression in c#

In this blog, I’m explaining about the [lambda expression](https://www.mindstick.com/articles/897/lambda-expression-in-c-sharp) in C#.

[Lambda expressions](https://www.mindstick.com/forum/159557/c-plus-plus-lambda-expressions-how-does-the-compiler-interpret-them) are [anonymous](https://www.mindstick.com/interview/1140/what-is-anonymous-class-in-java) methods, aimed at mainly addressing the "vertical problem" by replacing the machinery of anonymous [inner classes](https://www.mindstick.com/forum/159219/how-can-i-test-a-class-that-has-private-methods-fields-or-inner-classes) with a lighter-weight mechanism in [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) cases.

\
All lambda expressions use the lambda operator =>, which is read as “goes to”. The left side of the lambda operator specifies the input [parameters](https://www.mindstick.com/articles/87/passing-parameters-in-c-sharp) (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read “x goes to x times x.

(The => operator has the same precedence as [assignment](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment) (=))

A lambda expression is written in the following form

parameters => expression/{statements}

Lambda expressions in C#

##### Example

```
 Namespace LamdaExpression{      Class Program             {                        Static void Main(String[] args)                              {                                   int input;                                       input=Convert.toInt32(System.ReadLine());                                             Func<int,int,bool>  prime=null;                                               Prime=(x,y)=>(x=1 || y=0)?true :(x%y==0?false:prime(x,y-1);                                             Func<int,bool> isprime=x=>prime(x,x/2);                                         Console.Write(“{0} is a {1} prime number”, input,  isprime(input)?””:”not”)                              }                     }         }
```

---

Original Source: https://www.mindstick.com/blog/723/lambda-expression-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
