我有以下LINQ查詢:如何使用lambda運算符修改此linq查詢?
var files = (from d in new DirectoryInfo(@"c:\program files").GetDirectories()
where d.GetFiles().Count() > 10
where d.GetFiles().Count() < 100
select d
);
然而,正如你可以在上面看到,我打電話d.GetFiles()計數()的兩倍,這是其中=概念>運營商進來便利。
使用從jdehaan語法,我爲什麼不能直接做這樣的:
var files = (from d in new DirectoryInfo(@"c:\program files").GetDirectories()
where(x => x.GetFiles().Count() > 10) &&
(x.GetFiles().Count() < 100))
select d
);
我知道上面是愚蠢的,因爲我只是做我原來的查詢與d.GetFiles()計數。 (),但我很好奇使用Where而不是關鍵字Where的區別。
+1不使用lambdas,但依然:優秀的答案! – 2009-10-02 20:51:07
你也可以把兩個where語句結合起來,這可能更具可讀性。 – 2009-10-02 20:51:17
不錯。這樣可行。好奇,這是唯一的方法嗎? – Xaisoft 2009-10-02 20:51:30