开发者

How to set a readonly property?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜