设置一个属性的默认值

19 浏览
0 Comments

设置一个属性的默认值

是否可以在属性的主体之外设置默认值?最好使用注解。

[SetTheDefaultValueTo(true)]
public bool IsTrue { get; set; }
[SetTheDefaultValueTo(false)]
public bool IsFalse { get; set; }
public void Something()
{
    var isTrue = this.IsTrue;
    var isFalse = this.IsFalse;
}

有没有办法在属性的主体之外设置默认值?最好使用注解。

[SetTheDefaultValueTo(true)]
public bool IsTrue { get; set; }
[SetTheDefaultValueTo(false)]
public bool IsFalse { get; set; }
public void Something()
{
    var isTrue = this.IsTrue;
    var isFalse = this.IsFalse;
}

0