[csharp] nullable int to int

Costas

Administrator
Staff member
source : http://stackoverflow.com/a/5995418

JavaScript:
v2 = v1 ?? default(int);

Also, as of .NET 4.0, Nullable<T> has a "GetValueOrDefault()" method, which is a null-safe getter that basically performs the null-coalescing shown above, so this works too:

JavaScript:
v2 = v1.GetValueOrDefault();

//traditional
JavaScript:
if(v1.HasValue)
   v2=v1.Value
 
Top