Default values table
The following table shows the default values of value types.
Value type | Default value |
---|---|
bool |
false |
byte | 0 |
char | '\0' |
decimal | 0M |
double | 0.0D |
enum |
The value produced by the expression |
float | 0.0F |
int | 0 |
long | 0L |
sbyte | 0 |
short | 0 |
struct |
The value produced by setting all value-type fields to their default values and all reference-type fields to null . |
uint | 0 |
ulong | 0 |
ushort | 0 |
Remarks
You cannot use uninitialized variables in C#. You can initialize a variable with the default value of its type. You also can use the default value of a type to specify the default value of a method's optional argument.
Use the default value expression to produce the default value of a type, as the following example shows:
int a = default(int);
Beginning with C# 7.1, you can use the default
literal to initialize a variable with the default value of its type:
int a = default;
You also can use the default constructor or the implicit default constructor to produce the default value of a value type, as the following example shows. For more information about constructors, see the Constructors article.
int a = new int();
The default value of any reference type is null
. The default value of a nullable type is an instance for which the HasValue property is false
and the Value property is undefined.