2011-12-09 39 views

回答

2

A = B 12 ç

一個= C當B == NULL

A =如果B不爲NULL

下面是sraightforward實施CompanyProductSeriesId屬性獲取的, 我相信它爲B自我解釋說:

string returnValue; 

if (Request.QueryString["CPGId"] != null) 
{ 
    returnValue = Request.QueryString["CPGId"]; 
} 
else 
{ 
    if (ViewState["CPSId"] == null) 
    { 
     returnValue = ""; 
    } 
    else 
    { 
     returnValue = ViewState["CPGId"].ToString()); 
    } 
} 

return returnValue; 
1

??被稱爲空合併運算符,從MSDN -

「的??運算符稱爲空合併運算符和用於 定義空值類型或引用類型的默認值它 返回左側。如果操作數不爲null,則返回操作數;否則,返回右操作數 。

這是否幫助?

0

在這種情況下,它會返回Request.QueryString["CPGId"],或者,如果爲空,則返回(ViewState["CPSId"] == null ? "" : ViewState["CPGId"].ToString())

0

?? Operater僅適用於可空數據類型,如int?,DateTime?等

實施例:

int? a = 5; 
int b = a ?? 0; // out put will be 5 

int? c = null; 
int d = c ?? 0; // output will be 0;