【发布时间】:2012-04-25 14:06:22
【问题描述】:
我能够为类的普通默认属性分配默认值。 但我无法为类的静态默认属性分配默认值,如下所示:-
public class AppInstance
{
[DefaultValue(25)]
public static int AppType { get; set; }
}
当我调用 AppInstance.AppType 时,它总是返回 0 而不是 25。为什么?不使用私有变量声明如何解决?
【问题讨论】:
-
在 [static] 构造函数中赋值。
-
DefaultValue 是视觉组件的属性,通常由 Visual Studio 设计人员使用