2015-12-30 38 views

回答

0

The ?? operator is called the null-coalescing operator。如果操作數不爲null,則返回左側的操作數;否則返回右手操作數。

下面是該運營商的解釋:

int? x = null; 
// Set y to the value of x if x is NOT null; otherwise, 
// if x = null, set y to -1. 
int y = x ?? -1; 

因此,如果這Convert.ToDecimal(conn.LeavesRequests.Max(lr => (decimal?)lr.Id) + 1的值爲null,則txtId.Text將獲得價值1 IE右鍵操作或Convert.ToDecimal(conn.LeavesRequests.Max(lr => (decimal?)lr.Id) + 1

+0

也可以包含此鏈接https://msdn.microsoft.com/zh-cn/library/ms173224.aspx –

0

expr1 ?? expr2的評估值給出值如果expr1不爲null,則爲expr1。如果它爲空,則給出expr2的值。