问题:
As I understand it, in Linq the method FirstOrDefault()
can return a Default
value of something other than null.据我了解,在 Linq 中,方法FirstOrDefault()
可以返回非空值的Default
值。 What I haven't worked out is what kind of things other than null can be returned by this (and similar) method when there are no items in the query result.我还没有弄清楚的是,当查询结果中没有项目时,这个(和类似的)方法可以返回除 null 之外的哪些类型的东西。 Is there any particular way that this can be set up so that if there is no value for a particular query some predefined value is returned as the default value?有没有什么特别的方法可以设置它,以便如果特定查询没有值,则某些预定义值将作为默认值返回?
解决方案:
参考一: https://en.stackoom.com/question/sQgZ参考二: https://stackoom.com/question/sQgZ