What does this ?? notation mean here
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
What is the “??” operator for?
这里的
我说的对吗:使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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) }); } |
这是空合并运算符。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | var x = y ?? z; // is equivalent to: var x = (y == null) ? z : y; // also equivalent to: if (y == null) { x = z; } else { x = y; } |
即:如果
它是空合并运算符:http://msdn.microsoft.com/en-us/library/ms173224(vs.80).aspx
当第一个值(左侧)为空时,它提供一个值(右侧)。
意思是"如果