All type instances have a default value.
The default value for the predefined types is the result of a bitwise zeroing of memory:
Type | Default value |
---|---|
All reference types | null |
All numeric and enum types | 0 |
char type | '\0' |
bool type | false |
To get the default value for a type, use the default keyword:
decimal d = default (decimal);
The default value in a custom value type is the same as the default value for each field defined by the custom type.
You can refer to the following table for your reference.
Type | Default Values |
---|---|
sbyte, byte, short, ushort, int, uint, long,ulong | 0 |
char | '\x0000' |
float | 0.0f |
double | 0.0d |
decimal | 0.0m |
bool | false |
struct | all value types to their default values |
all reference type | null |
enum e | 0( converted to type e) |