c# - What does this ?? notation mean here -
possible duplicate:
what “??” operator for?
what ?? notation mean here?
am right in saying: use id, if id 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) }); }
that's null-coalescing operator.
var x = y ?? z; // equivalent to: var x = (y == null) ? z : y; // equivalent to: if (y == null) { x = z; } else { x = y; } ie: x assigned z if y null, otherwise assigned y.
in example, customerid set "alfki" if null.
Comments
Post a Comment