User Tools

Site Tools


notes:csharp:default

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

notes:csharp:default [2015/12/04] (current)
admin created
Line 1: Line 1:
 +====== Default Values in C# ======
 +
 +Obtain the default value using the //default value expression//​ (useful with generics):
 +<code csharp>
 +decimal d = default(decimal);​
 +</​code>​
 +
 +Obtain the default value using a method of the //Convert// class:
 +<code csharp>
 +DateTime d = Convert.ToDateTime(null);​
 +Console.WriteLine(d);​ // 0001-01-01 12:00:00 AM
 +</​code>​
 +
 +
 +^  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