Set a default value to a property

后端 未结 5 1585
你的背包
你的背包 2021-02-11 21:58

Is it possible to set a default value without the body of a property? Preferably with annotations.

[SetTheDefaultValueTo(true)]
public bool IsTrue { get; set; }
         


        
5条回答
  •  醉酒成梦
    2021-02-11 22:18

    Old thread. Looks like Microsoft heard and this feature is available in .Net Framework 4.6+ (C# 6+) You can use it like

    public string MyValue { get; set; } = "My Default";
    

提交回复
热议问题