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