User Tools

Site Tools


notes:csharp:default

Default Values in C#

Obtain the default value using the default value expression (useful with generics):

decimal d = default(decimal);

Obtain the default value using a method of the Convert class:

DateTime d = Convert.ToDateTime(null);
Console.WriteLine(d); // 0001-01-01 12:00:00 AM
Type Default value
reference types (including String) null
numeric and enum types 0
char '\0'
bool false
DateTime DateTime.MinValue
notes/csharp/default.txt · Last modified: 2015/12/04 by admin