問題:
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