C# Interview Question #108
What is the default keyword in C#?
Types, Equality, Immutability & Internals Senior Advanced
Quick Interview Answer
The default keyword produces the default value of a type. For numeric value types it is zero, for bool it is false, and for reference types it is null.
Detailed Explanation
The default keyword produces the default value of a type. For numeric value types it is zero, for bool it is false, and for reference types it is null.
In generic code, default or default(T) is useful when the actual type parameter is not known at compile time.
With nullable reference types enabled, returning default for an unconstrained generic parameter may require careful nullability design.
Code Example
int number = default; // 0
bool flag = default; // false
string? text = default; // null
T? GetDefault<T>() => default;