??运算符:
variable ?? defaultValue
相当于
variable == null ? defaultValue : variable
code 1:
// y = x,unless x is null,in which case y=-1
int y = x ?? –1;
code 2:
DatePicker daySelection;
DateTime date = daySelection.SelectedDate ?? DateTime.Today;
code1,很明显,除非x=null时y才能-1,否则y=x;
code2,除非daySelection.SelectedDate=null,date=DateTime.Today,否则date=daySelection.SelectedDate=。
参考网址: