I know that Lambda Expressions is not just for LINQ. But what are the possible scenarios which we can use Lambda Expression in? what is the code of these examples without Lambda Expression?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Let’s say you have a list of
Personobjects and want to make aDictionary<int, string>out of it to be able to look up person’s name by his SSN or something.With
ToDictionarymethod it’s easy:The alternative is to create a dictionary and then use a
foreachloop:Which is kinda wordy and hides the intent.
You can use
ToDictionarybut without lambda expressions:which is obviously not so concise.
You could go with anonymous delegates:
but it doesn’t compare with lambda expressions in conciseness.
I wouldn’t want to use any LINQ extension methods if lambda expressions weren’t implemented in the language because it would requite a lot of unnecessary code.