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

后端 未结 21 1423
终归单人心
终归单人心 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:30

    Just found this looking for something different, but in the new C# version, you can use an even shorter version for that:

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

提交回复
热议问题