gpt4 book ai didi

c# - 哪个是使用 LINQ 的更好方法?

转载 作者:太空狗 更新时间:2023-10-29 22:17:03 25 4
gpt4 key购买 nike

我有这两行,它们做的事情完全一样。但是写的不一样。哪个是更好的做法,为什么?

firstRecordDate = (DateTime)(from g in context.Datas
select g.Time).Min();

firstRecordDate = (DateTime)context.Datas.Min(x => x.Time);

最佳答案

there is no semantic difference between method syntax and query syntax. In addition, some queries, such as those that retrieve the number of elements that match a specified condition, or that retrieve the element that has the maximum value in a source sequence, can only be expressed as method calls.

http://msdn.microsoft.com/en-us/library/bb397947.aspx

另请参阅此处:.NET LINQ query syntax vs method chain

这归结为您对什么感到满意以及您发现什么更具可读性。

关于c# - 哪个是使用 LINQ 的更好方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7124169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com