Assign Default Value to Variable if Second Variable is Null


/ Published in: C#
Save to your folder(s)

If you set the int keyword to be Nullable, then when x is declared there it's set to null.
On the second line, the "??" are saying if x is null then assign -1 instead.


Copy this code and paste it in your HTML
  1. Nullable<int> x;
  2.  
  3. int y = x ?? -1;

Report this snippet


Comments


You need to login to view comments.