|

Difference between LINQ and lambda expression

I have stuck at this field for a long time. Today it suddenly becomes clear to me: LINQ and lambda expressions are to very different things (though they complements each other on many occasions).

Lambda expression

Lambda expression, to sum up, is only about the operator “=>” (read as “goes to”). It serves as a shorthand for anonymous function (usually used to write short expressions like “x => x % 2 == 0” to find even numbers). It will be automatically typed as either an Expression, a delegate or a Func depending on where it is used.

LINQ

LINQ is like SQL for objects. It can query arrays, list or any other enumerable objects. It’s sort of an advanced for loops with SQL-like operations like sorting, grouping and of course, lambda expression support. Usual syntax is “from <iterator name> in <data> where <condition on iterator> select <iterator>”

Leave a Reply

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