Posted By

mordecaix7 on 12/30/08


default null values nullable integers

Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


Assign Default Value to Variable if Second Variable is Null

 / Published in: C#

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.

  1. Nullable<int> x;
  3. int y = x ?? -1;

Report this snippet  

You need to login to post a comment.