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

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -