create null-able value type
Published: 26. September 2011 | Updated: 26. October 2011License: Microsoft Public License (MS-PL)
Categories: Framework » Types
Tags: C#
Declaration
int? number = null; // or Nullable<int> number = null;
Check for null
if(number.HasValue) ... // or if(number != null) ...
Get value
int nonNullable = (int)number; // or int nonNullable = number.Value; // or int nonNullable = number.GetValueOrDefault();
| Send us feedback about this snippet » |





