Part 99 Lambda expression in c#

preview_player
Показать описание
Text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

Slides

All C# Text Articles

All C# Slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

In this video we will discuss, what lambda expressions are with an example. We will be working with the same example that we worked with in Part 98.

Anonymous methods and Lambda expressions are very similar. Anonymous methods were introduced in C# 2 and Lambda expressions in C# 3.

To find an employee with Id = 102, using anonymous method
Employee employee = listEmployees.Find(delegate(Employee Emp) { return Emp.ID == 102; });

To find an employee with Id = 102, using lambda expression
Employee employee = listEmployees.Find(Emp =] Emp.ID == 102);

You can also explicitly specify the Input type but not required
employee = listEmployees.Find((Employee Emp) =] Emp.ID == 102);

Notice that with a Lambda expression you don't have to use the delegate keyword explicitly and you dont't have to specify the input parameter type explicitly. The parameter type is inferred. Lambda expressions are more convenient to use than anonymous methods. Lambda expressions are particularly helpful for writing LINQ query expressions.

=] is called lambda operator and read as GOES TO.

In most of the cases Lambda expressions supersedes anonymous methods. To my knowledge, the only time I prefer to use anonymous methods over lambdas is, when we have to omit the parameter list when it's not used within the body.

Anonymous methods allow the parameter list to be omitted entirely when it's not used within the body, where as with lambda expressions this is not the case.

For example, with anonymous method notice that we have omitted the parameter list as we are not using them within the body
Button1.Click += delegate
{
MessageBox.Show("Button Clicked");
};

The above code can be rewritten using lambda expression as shown below. Notice that with lambda we cannot omit the parameter list.
Button1.Click += (eventSender, eventAgrs) =]
{
MessageBox.Show("Button Clicked");
};
Рекомендации по теме
Комментарии
Автор

You are Simply doing a Great Job Venkat, I watch your viedos over and over, Interview preparations means Kud Venkat Videos.... Simply

fanendra
Автор

Sir, I am not kidding when I say this, I have a job now thanks to your tutorials and all the knowledge I gained from them. Thank you and continue the amazing work !!!

sadhanakalyanaraman
Автор

Nice tutorial. I always need a refresher on this topic and chaining linq operators

Nicky
Автор

I was looking for an expression of lambda. Several sites just confused me, but this was great.

bennyboyAF
Автор

Venkat, I came across one of your video presentations today. I watched several others also - each was thorough, concise, and relevant. Thank you for providing a valuable resource to .NET developers.

scottm
Автор

I was really stuck on this today. Thanks for the great explanation! I get it now!

Psoewish
Автор

Terrific video!!  Very clear and thorough explaination of Lambda Expressions!  I also like how you explain things many different ways with different examples as well as show what is going on behind the scenes in your examples.

DodgerDude
Автор

Just amazing!! Thank you very much, sir!!!

MSKassiste
Автор

Thank you so very much for your very clear style, and for the effort you put forth in making these videos available. I have bookmarked your tutorial series and am eager to recommend them when ever I can!

RossYlitalo
Автор

Perfect explanation, i appreciate your hard work!!!

drspyqwerty
Автор

I really appreciate you Venkat for uploading these helpful vidoes

TheAviram
Автор

Simply awesome Kudvenkat !. Always love your videos.

HassanKhan-geik
Автор

Thank you very much. I spend a lot of time to learn lambda expression, and with your lesson I did it in 11 minutes. 

Carlitosyohoho
Автор

Thank you very much, i appretiate your video and effort :)

gonzaloportada
Автор

Thanks, it very good. looking for more videos

chandrashekharreddyennam
Автор

I really appreciate you Venkat for uploading these helpful vidoes.thanks a

pawan
Автор

thaaanks a lot for a good video, I, m waiting for a new videos every time :) very good explanation, thanks again

KamilIbadov
Автор

Venkat,
could you please make a video on how to use Inumerable and Inumerator please ? I need to understand those two interfaces.... thank you million times for the clear and detailed explanation.

mohammedalmukhtar
Автор

Thanks a lot, infact the way you explained is awesome :)

nambukarthyraveendran
Автор

Please add more videos..
I am looking forward to the next videos.
Thanks

sahilintell