Possible Duplicate:
default value for a static property
I am able to assign default value for a normal default property of a class.
But i am not able to assign default value for a static default property of a class like below:-
public class AppInstance
{
[DefaultValue(25)]
public static int AppType { get; set; }
}
When I call AppInstance.AppType, it always return 0 instead of 25. Why? How can i solve it without using a private variable declaration?
The
DefaultValueAttributeonly tells theWinFormsdesigner which value is the default value of a property of the form or of a control. If the property has another value, this value will appear bold in the properties window. But it will actually not set the value.You must assign it a value in the static constructor