c# private set
来源:互联网 发布:北京高瓴投资大数据 编辑:程序博客网 时间:2024/06/04 21:34
A private setter is useful if you have a read only property and don't want to explicitly declare the backing variable.
So:
public int MyProperty{ get; private set;}
is the same as:
private int myProperty;public int MyProperty{ get { return myProperty; }}
For non auto implemented properties it gives you a consistent way of setting the property fromwithin your class so that if you need validation etc. you only have it one place.
To answer your final question the MSDN has this to say on private setters:
However, for small classes or structs that just encapsulate a set of values (data) and have little or no behaviors, it is recommended to make the objects immutable by declaring the set accessor as private.
http://stackoverflow.com/questions/3847832/understanding-private-setters
0 0
- c# private set
- Working Set,Private Bytes 区别
- C# public、protected、private
- Working set和Private bytes区别
- private bytes working set virtual bytes
- Working set和Private bytes区别
- JAVA封装 private,set,get的用法
- C# public、protected、internal 、private
- process explorer中的visual size vs working set; private bytes vs WS private
- set one directory to private for one user
- unable to set private key file: client.pem type PEM
- java封装中的private关键字和set,get方法
- Private Set Intersection(PSI)简介和资料分享
- C# 中public、protected、internal 、private学习
- C#中,public,protected,private,static
- C# 方法默认访问级别 : private
- C# 关键字 public protect private internal
- C#修饰符private,protect的区别
- 多路复用I/O
- 我的敏捷、需求分析、UML、软件设计电子书 - 下载(持续更新中)
- 顺序输出
- 读书笔记——OP放大电路设计
- 旅行,写作,编程 :IT文艺青年的生活态度
- c# private set
- DB2 连接方法
- 图形API的两种模式
- 最近电信.网通.不同省市的用户访问服务出现异常
- 2013全球十大管理咨询公司
- hive 去重数据
- 回调函数例子
- 山东理工大学ACM平台题答案关于C语言 1231 绝对值排序
- C#两个数组合并