Setting the default value of a DateTime Property to DateTime.Now inside the System.ComponentModel Default Value Attrbute

后端 未结 21 1393
终归单人心
终归单人心 2020-11-29 22:53

Does any one know how I can specify the Default value for a DateTime property using the System.ComponentModel DefaultValue Attribute?

for example I try this:

21条回答
  •  失恋的感觉
    2020-11-29 23:06

    I faced the same issue, but the one which works for me best is below:

    public DateTime CreatedOn { get; set; } = DateTime.Now;
    

提交回复
热议问题