34

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.

4
  • 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. Commented Oct 12, 2011 at 0:54
  • 9
    Check out ideone.com for an online compiler Commented Oct 12, 2011 at 1: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). Commented Sep 22, 2013 at 15:54
  • dotnetfiddle.net is also a nice online compiler. Commented Jun 26, 2015 at 16:37

1 Answer 1

51

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.