CSharp examples for Language Basics:Variable
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 |
The default value in a custom value type (i.e., struct) is the same as the default value for each field defined by the custom type.
You can obtain the default value for any type with the default keyword:
using System;/* www . j a va2 s . co m*/ class Test { static void Main(){ decimal d = default (decimal); Console.WriteLine (d); } }