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

Default values for 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 assign the default value of an int variable.

C Sharp (C#)
int number = [1];
Drag options to blanks, or click blank then click option'
Adefault(int)
B0
Cnull
Dint()
Attempts:
3 left
💡 Hint
Common Mistakes
Using null for value types like int causes errors.
Using 0 directly is correct but the task asks for default keyword.
2fill in blank
medium

Complete the code to assign the default value of a bool variable.

C Sharp (C#)
bool isActive = [1];
Drag options to blanks, or click blank then click option'
Atrue
Bnull
Cdefault(bool)
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using null for bool causes errors because bool is a value type.
Using true is not the default value.
3fill in blank
hard

Fix the error in the code to assign the default value of a string variable.

C Sharp (C#)
string name = [1];
Drag options to blanks, or click blank then click option'
A""
Bdefault(string)
Cnull
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 causes a type error.
Using empty string "" is not the default value.
4fill in blank
hard

Fill both blanks to create a method that returns the default value of a generic type T.

C Sharp (C#)
public T GetDefaultValue<[1]>() {
    return [2];
}
Drag options to blanks, or click blank then click option'
AT
Bdefault(T)
Cvoid
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using void as a generic type parameter is invalid.
Returning null may cause errors for value types.
5fill in blank
hard

Fill all three blanks to create a dictionary with keys as strings and values as default values of type int.

C Sharp (C#)
var defaults = new Dictionary<string, int> {
    {"one", [1],
    {"two", [2],
    {"three", [3]
};
Drag options to blanks, or click blank then click option'
Adefault(int)
B0
Cdefault
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using null causes errors because int is a value type.
Using 0 is correct but the task asks for default keyword.