0
0
C Sharp (C#)programming~10 mins

Nullable value types in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a nullable integer variable.

C Sharp (C#)
int[1] number = null;
Drag options to blanks, or click blank then click option'
A!
B?
C*
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!' instead of '?' to declare nullable types.
Trying to assign null to a non-nullable value type.
2fill in blank
medium

Complete the code to check if a nullable integer has a value.

C Sharp (C#)
if (number[1]) {
    Console.WriteLine("Has value");
}
Drag options to blanks, or click blank then click option'
A.HasValue
B== null
C!= null
D.Value
Attempts:
3 left
💡 Hint
Common Mistakes
Using '== null' to check for value presence instead of 'HasValue'.
Using '.Value' without checking if the value exists.
3fill in blank
hard

Fix the error in accessing the value of a nullable integer safely.

C Sharp (C#)
int value = number[1];
Drag options to blanks, or click blank then click option'
A.Value
B== null
C!
D?? 0
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.Value' without checking for null, causing exceptions.
Using '!' which is not valid here.
4fill in blank
hard

Fill both blanks to declare a nullable double and assign a value if it is null.

C Sharp (C#)
double[1] temperature = null;
double actualTemp = temperature [2] 25.0;
Drag options to blanks, or click blank then click option'
A?
B??
C+
D!
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '??' for default value.
Forgetting to make the type nullable.
5fill in blank
hard

Fill all three blanks to create a nullable bool, check if it has value, and get the value or default to false.

C Sharp (C#)
bool[1] isActive = null;
if (isActive[2]) {
    bool status = isActive[3] false;
}
Drag options to blanks, or click blank then click option'
A?
B.HasValue
C??
D!
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!' instead of '?' for nullable.
Checking null with '== null' instead of '.HasValue'.
Using '+' instead of '??' for default value.