33

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.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Eugene
  • 10,957
  • 20
  • 69
  • 97
  • 1
    Ye...you're right. I'm not at a compiler though...so I thought to ask. Will test these in the future rather than ask...question can be deleted if moderator wants. – Eugene Oct 12 '11 at 00:54
  • 9
    Check out http://ideone.com/ for an online compiler – Scott Oct 12 '11 at 01:47
  • 20
    Still, I think the community can agree that it is useful to have even the most simple questions answered so that instead of 30, it takes no longer than 5 seconds to resolve a query (at least for the rest of us). – Marco Toniut Sep 22 '13 at 15:54
  • https://dotnetfiddle.net/ is also a nice online compiler. – Jeff B Jun 26 '15 at 16:37

1 Answers1

50

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
Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272