开发者

LINQ - Selecting a property of an object for further use rather than dereferencing it in each place

开发者 https://www.devze.com 2023-01-13 05:47 出处:网络
string output = (from s in abc.longs 开发者_如何学JAVAgroup s by DateTime.FromFileTimeUtc(s).Minutes < 1
string output = (from s in abc.longs
 开发者_如何学JAVA                        group s by DateTime.FromFileTimeUtc(s).Minutes < 1
                 .... // so on so forth

The question I have, is I do "DateTime.FromFileTimeUtc(s) like 10 times here, is there any way to do

from s in abc.longs
   t = DateTime.FromFileTimeUtc(s).Minutes
   group by t < 1


Yes, using the let keyword, which let you declare a symbol you can use later on in the query:

from s in abc.longs
let t = DateTime.FromFileTimeUtc(s).Minutes
group by t < 1

You can find a lot of examples using Google.

0

精彩评论

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