Eugene
Eugene

Reputation: 11535

default(Nullable(type)) vs default(type)

In C#, is there a difference between default(Nullable<long>) (or default(long?)) and default(long) ?

Long is just an example, it can be any other struct type.

Upvotes: 34

Views: 16950

Answers (1)

Jeff Mercado
Jeff Mercado

Reputation: 134901

Well yes. The default value of a nullable or other reference type is null while the default value for a long or other value type is 0 (and any other members set to their defaults).

In this case:

default(Nullable<long>) == null
default(long?) == null

default(long) == 0L

Upvotes: 51

Related Questions