开发者

Comparison : LINQ vs LAMBDA Expression [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_如何学运维 Closed 12 years ago.

I need a discussion regarding the Performance of LINQ and Lambda Expression.

Which one is better?


I guess you mean query expression when talking about LINQ here.

They are equivalent. The compiler changes the query expression into the equivalent Lambda expression before compiling it, so the generated IL is exactly the same.

Example

var result = select s from intarray
             where s < 5
             select s + 1;

is exactly the same as

var result = intarray.Where( s => s < 5).Select( s => s+1);

Note that if you write the query expression like this:

var result = select s from intarray
             where s < 5
             select s;

It's converted to:

var result = intarray.Where( s => s < 5);

The final call to Select is omitted because it's redundant.


a quick comparison in reflector would probably do the trick. However, from a 'preference' standpoint, I find lambda statements easier to follow and write and use them across the board whether it be with objects, xml or whatever.

If performance is negligible, i'd go with the one that works best for you.

i actually started off a little topic looking at linq methods which may be of interest:

What's your favourite linq method or 'trick'

cheers..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜