默认值属性不符合我的自动属性工作 [英] DefaultValue attribute is not working with my Auto Property

查看:98
本文介绍了默认值属性不符合我的自动属性工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的自动属性。

  [默认值(真)]
公共BOOL RetrieveAllInfo {搞定;组; }

当我尝试使用它的$ C $词里面找到默认假的,是我认为这是默认值设置为布尔变量,没有任何人有什么线索是错的!?


解决方案

将默认值属性只是用来告诉Visual Studio的设计师(如设计表单时),什么属性的默认值是

。它不会设置code属性的实际默认值。

在此处了解详情: http://support.microsoft.com/kb/311339

I have the following Auto Property

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

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!?

解决方案

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.

More info here: http://support.microsoft.com/kb/311339

这篇关于默认值属性不符合我的自动属性工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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