Search code examples
c#propertiesattributesdefault-valueautomatic-properties

DefaultValue attribute is not working with my Auto Property


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


Solution

  • 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