LINQ - Selecting a property of an object for further use rather than dereferencing it in each place
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.
精彩评论