Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DefaultValue attribute is not working with my Auto Property

Tags:

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

like image 404
Ahmed Magdy Avatar asked Dec 30 '09 14:12

Ahmed Magdy


People also ask

What is default value of attribute?

A member's default value is typically its initial value. From this, you may conclude that if you set the DefaultValue attribute for a property, the property is initialized to that value. However, you should set the property's DefaultValue attribute equal to its initialized value.

How do I set default value in property?

Right-click the control that you want to change, and then click Properties or press F4. Click the All tab in the property sheet, locate the Default Value property, and then enter your default value. Press CTRL+S to save your changes.


1 Answers

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

like image 71
Philippe Leybaert Avatar answered Jan 03 '23 12:01

Philippe Leybaert