Why to use lambda expression when we have LINQ queries just to shorten the length of code , increase the speed of development or is there any other reason which can only be achieved by Lambda expression & not by LINQ queries.
相关问题
- Why wrapping a function into a lambda potentially
- Generating powerset in one function, no explicit r
- Check if tie in count of lists using linq
- Trouble with OR in Sharepoint CAML
- C# to VB - How do I convert this anonymous method
相关文章
- 想问问Linq中有没有根据条件选择要不要关联表。
- Why doesn't C11 support lambda functions
- Why do I need a ToList() to avoid disposed context
- LINQ .Include() properties from sub-types in TPH i
- Can a method chain be called LINQ?
- Get grouped comma separated values with linq
- How does a LINQ expression know that Where() comes
-
Creating dynamic Expression
>
There are some LINQ extension methods which do not have counterparts in LINQ query expressions, and will require the use of Lambda Expressions. A good example is Enumerable.ToLookup - if you want to create an ILookup, you need to use lambdas to generate this.
Query expressions only cover a small subset of the LINQ operators, and are only applicable when you have the actual expression involved to hand, rather than (say) having a
Func<T, bool>
to act as the predicate, in which case things become ugly. So instead of writing:I'd much rather write:
There are various other cases where using non-query expression syntax is simpler, particularly if your query only uses a single operator.
Query expressions are effectively translated into non-query expressions, so anything you can do in query expressions can be expressed in non-query expressions. Use query expressions where they make the code simpler and more readable; don't use them where they don't.
I have more information about how query expressions work in a blog post that you may be interested in.