Possible Duplicate:
What do two question marks together mean in C#?
谁能解释这种语法。
protected string CompanyProductSeriesId
{
get
{
return Request.QueryString["CPGId"]
?? (ViewState["CPSId"] == null
? ""
: ViewState["CPGId"].ToString());
}
}
我想忍受??用这种语法。
最佳答案
A = B ?? C
如果B == NULL,则A = C
如果B不为NULL,则A = B
下面是CompanyProductSeriesId
属性获取器的简单实现,
我相信这是不言自明的:
string returnValue;
if (Request.QueryString["CPGId"] != null)
{
returnValue = Request.QueryString["CPGId"];
}
else
{
if (ViewState["CPSId"] == null)
{
returnValue = "";
}
else
{
returnValue = ViewState["CPGId"].ToString());
}
}
return returnValue;
关于c# - 什么是 ??在我的属性(property)? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8446432/