Search code examples
c#default-valuemsdnxelement

Determining the default() value of a class in C#


MSDN's documentation on standard C# classes doesn't seem to contain what the default value for that type is. Am I not looking in the right place? Specifically, I am trying to figure out what the default value of XElement is.

I can always run my program and figure it out then, but I'd like a way to avoid that, if possible.

Edit: This page shows the default values for the native types, but I'm wondering about complex types.


Solution

  • The default value for all reference types is null.As stated in here:

    The solution is to use the default keyword, which will return null for reference types and zero for numeric value types.