在.net framework下属性可是通过public string str{ get; set; }这种方式迅速操作了,可是经常碰到一些诸如只读啊,默认值啊,怎么办呢?
public string str{ get; private set; }可以设为只读
[DefaultValue(false)]
public bool isSuccess { get; set; }
则可设默认值(添加System.ComponentModel命名空间)
实验未生效。。。。
MSDN说明:You can create a DefaultValueAttribute with any value. A member's default value is typically its initial value. A visual designer can use the default value to reset the member's value. Code generators can use the default values also to determine whether code should be generated for the member.
也就是说,虽然设了”默认值“,但是不提供初始话,这让我有点百思不得其解~~~