简体   繁体   English

在C#中确定类的default()值

[英]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. MSDN关于标准C#类的文档似乎不包含该类型的default值。 Am I not looking in the right place? 我不是在寻找合适的地方吗? Specifically, I am trying to figure out what the default value of XElement is. 具体来说,我试图弄清楚XElementdefault值是什么。

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. 编辑: 此页面显示本机类型的默认值,但我想知道复杂类型。

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. 解决方案是使用default关键字,它将为引用类型返回null ,为数值类型返回零。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM