DefaultValue attribute is not working with my Auto Property

Ahmed Magdy picture Ahmed Magdy · Dec 30, 2009 · Viewed 17.8k times · Source

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

Answer

Philippe Leybaert picture Philippe Leybaert · Dec 30, 2009

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