Nullable types allow you to create a value type variable that can be marked as valid or invalid so that you can make sure a variable is valid before using it. Regular value types are called non-nullable types.
The important things you need to know about nullable type conversions are the following:
• There is an implicit conversion between a non-nullable type and its nullable version. That is, no cast is needed.
• There is an explicit conversion between a nullable type and its non-nullable version.
For example, the following lines show conversion in both directions. In the first line, a literal of type
int is implicitly converted to a value of type int? and is used to initialize the variable of the nullable type.
In the second line, the variable is explicitly converted to its non-nullable version.
int? myInt1 = 15; // Implicitly convert int to int?
int regInt = (int) myInt1; // Explicitly convert int? to int
int? myInt1 = 15; // Implicitly convert int to int?
int regInt = (int) myInt1; // Explicitly convert int? to int