Lambda Expression


C# 3.0(. NET 3.5) introduced the lambda expression along with LINQ . The lambda expression is a shorter way of representing anonymous method using some special syntax.

By using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls. Lambda expressions are particularly helpful for writing LINQ query expressions. 

To create a lambda expression, you specify input parameters (if any) on the left side of the lambda operator =>, and you put the expression or statement block on the other side. 

Example:- 


namespace lamdaexpdemo
{
class Program
{
static void Main(string[] args)
{
List<string> lst = new List<string>();
lst.Add("Utpal");
lst.Add("lade");


// anonymous method


string name = lst.Find(delegate(string na)
{
return na.Equals("Utpal");
});


// lambda E
xpression 

 string lsname = lst.Find(namels=>namels.Equals("lade"));

if(name!=null && lsname!=null)
{
Console.Write("Name found");
}
else{
Console.Write("Name not found");
}
Console.ReadKey();
}
}
}

No comments:

Post a Comment

Xamarin Android Project App

Xamarin Android Project App 1. Xamarin -- Make a CALCULATOR Android App   https://drive.google.com/open?id=0B8OPCXLrtKPmWC1FWWtFM2lraVk...