Posts o[csharp] nullable int to int
Post
Cancel

o[csharp] nullable int to int

source : http://stackoverflow.com/a/5995418

1
v2 = v1 ?? default(int);

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

1
v2 = v1.GetValueOrDefault();

//traditional jsif(v1.HasValue) v2=v1.Value </t>

origin - http://www.pipiscrew.com/?p=2757 csharp-nullable-int-to-int

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags