DefaultValue 属性不适用于我的 Auto 属性 [英] DefaultValue attribute is not working with my Auto Property

查看:24
本文介绍了DefaultValue 属性不适用于我的 Auto 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下自动属性

[DefaultValue(true)]
public bool RetrieveAllInfo { get; set; }

当我尝试在代码中使用它时,我发现默认的 false 是 false 我认为这是 bool 变量的默认值,有没有人有知道出了什么问题!?

when I try to use it inside the code i find the default false for is false I assume this is the default value to a bool variable, does anyone have a clue what is wrong!?

推荐答案

DefaultValue 属性仅用于告诉 Visual Studio 设计人员(例如在设计表单时)属性的默认值是什么.它不会在代码中设置属性的实际默认值.

The DefaultValue attribute is only used to tell the Visual Studio Designers (for example when designing a form) what the default value of a property is. It doesn't set the actual default value of the attribute in code.

更多信息:http://support.microsoft.com/kb/311339

这篇关于DefaultValue 属性不适用于我的 Auto 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆