我可以:
var something = things.Where(thing => thing.stuff == yup);
var somethingelse = something.Select(thing => thing.otherstuff);
或者
var something = from thing in things
where thing.stuff == yup
select thing;
var somethingelse = from thing in something
select thing.otherstuff;
显然,如果这是现实世界,那么关键字版本的好处是:
var somethingelse = from thing in something
where thing.stuff == yup
select thing.otherstuff;
但是当然你可以争辩说你可以这样做:
var somethingelse = things.Where(thing => thing.stuff == yup)
.Select(thing => thing.otherstuff);
无论如何,问题本身:使用这些变体中的每一个的优点/缺点是什么?它们是否相同但只是语法代码端不同?如果您结合两个方法版本(即上面的 where/select),它是否比使用关键字语法将两者结合到一行中效率低?
我喜欢 LINQ,我不想失去任何可以通过使用一种或另一种类型获得的效率。