Complete the code to declare a nullable integer variable.
int[1] number = null;In C#, adding a ? after a value type makes it nullable.
Complete the code to check if a nullable integer has a value.
if (number[1]) { Console.WriteLine("Has value"); }
The HasValue property returns true if the nullable variable contains a value.
Fix the error in accessing the value of a nullable integer safely.
int value = number[1];The null-coalescing operator ?? provides a default value if number is null, avoiding exceptions.
Fill both blanks to declare a nullable double and assign a value if it is null.
double[1] temperature = null; double actualTemp = temperature [2] 25.0;
The ? makes the double nullable, and ?? assigns 25.0 if temperature is null.
Fill all three blanks to create a nullable bool, check if it has value, and get the value or default to false.
bool[1] isActive = null; if (isActive[2]) { bool status = isActive[3] false; }
The ? makes the bool nullable, .HasValue checks if it has a value, and ?? provides a default if null.