这是什么作用??这里的符号意思是
可能的重复:
什么是“??”运算符?
这里的 ??
符号是什么意思?
我说得对吗:使用id
,但如果id
为空,则使用字符串“ALFKI”?
public ActionResult SelectionClientSide(string id)
{
ViewData["Customers"] = GetCustomers();
ViewData["Orders"] = GetOrdersForCustomer(id ?? "ALFKI");
ViewData["id"] = "ALFKI";
return View();
}
[GridAction]
public ActionResult _SelectionClientSide_Orders(string customerID)
{
customerID = customerID ?? "ALFKI";
return View(new GridModel<Order>
{
Data = GetOrdersForCustomer(customerID)
});
}
Possible Duplicate:
What is the “??” operator for?
What does the ??
notation mean here?
Am I right in saying: Use id
, but if id
is null use string "ALFKI" ?
public ActionResult SelectionClientSide(string id)
{
ViewData["Customers"] = GetCustomers();
ViewData["Orders"] = GetOrdersForCustomer(id ?? "ALFKI");
ViewData["id"] = "ALFKI";
return View();
}
[GridAction]
public ActionResult _SelectionClientSide_Orders(string customerID)
{
customerID = customerID ?? "ALFKI";
return View(new GridModel<Order>
{
Data = GetOrdersForCustomer(customerID)
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是 空合并运算符。
即:
xy
为null
,code>将被分配z
,否则将被分配y
。因此,在您的示例中,如果
customerID
最初为null
,则它将设置为"ALFKI"
。That's the null-coalescing operator.
ie:
x
will be assignedz
ify
isnull
, otherwise it will be assignedy
.So in your example,
customerID
will be set to"ALFKI"
if it was originallynull
.这是空合并运算符:
http://msdn.microsoft.com/en-us/ library/ms173224(VS.80).aspx
当第一个值(左侧)为空时,它提供一个值(右侧)。
It's the null coalescing operator:
http://msdn.microsoft.com/en-us/library/ms173224(VS.80).aspx
It provides a value (right side) when the first value (left side) is null.
它的意思是“如果
id
或customerID
为null
,则假装它是"ALFKI"
。It means "if
id
orcustomerID
isnull
, pretend it's"ALFKI"
instead.