What is Lambda Expressions? Basics Explained.

You keep wondering what it is and it may scare you at first. It is quite simple, in fact, just another thing to understand.
Lambda expressions can certainly be complex, but, start with a simple q => q.A == a; Get it yet?
If not, not a problem, here’s a more humanly understandable description: if you’ve got a “q”, and it’s got a property that happens to be called “A”, and that property equals to your “a”… well, the part to the right of that pointy “=>” thing means it’s just became true. Now, this is no assignment, your q on the left of that lovely thing is what you feed in so, your whole expression becomes a result. You are basically saying, “I got a ‘q'” – given that ‘q’, compare it’s property to something and return me something; and I’ll then decide on what to do. And that, my friend, depends on the function you are using the lambda on. Go or give:

var result = list.Where(q => q.Active = true);

In this case, the list is a collection of some objects that have Active property, and you are saying “given a ‘q’, if ‘q.Active’ is true, get it there in the resultset”.

Wait up for more!

This entry was posted in Basics and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *