开发者

How to set a readonly property?

开发者 https://www.devze.com 2023-01-02 21:58 出处:网络
Can you say how to set readonly property in property method(get and se开发者_开发技巧t).You can either only give your property a getter:

Can you say how to set readonly property in property method(get and se开发者_开发技巧t).


You can either only give your property a getter:

private string _name;

public string Name { get { return _name; } }

Or you can give the accessors different visibilities:

public string Name { get; private set; }


You simply omit the setter:

 private string myField;
 public string MyReadOnlyProperty {get { return myField;}}
0

精彩评论

暂无评论...
验证码 换一张
取 消