5.5 Exercise 5.3 Nullable and value types
-
Add the following code at the end of your
Mainmethod:1 2 3 4 5 6 7 8 9
int integer1 = 3; int integer2 = 3; int? integer3 = 3; int? integer4 = 3; Console.WriteLine(integer1); Console.WriteLine(integer2); Console.WriteLine(integer3); Console.WriteLine(integer4);- The first line assigns the value 3 to a variable of the primitive type.
- The second line also uses a primitive type.
- The third and fourth lines create nullable integers. The
?makes the value type nullable. - Note that
intandint?can both be printed withConsole.WriteLine; the compiler handles the conversion. int?can holdnull, which primitiveintcannot.
-
Run your program and note that the value 3 is displayed four times.