FirstOrDefault:除 null 以外的默认值 - FirstOrDefault: Default value other than null

问题:

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章