不总是.
Get返回开发人员认为属性应该是的值,并set更改开发人员认为适合存储数据的任何内容.通常,属性和内部字段之间存在一对一的映射,但并非总是如此.
int UltimateAnswer {get {return 42;}} // no internal field at all
int Direct
{
get {return _direct;}
set {_direct = value;}
}
int WithConversion
{
get {return _stored * 100;}
set { _stored = value / 100;}
}
int AutoFiled {get;set;} // this one directly maps to automatically created field.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
253 次 |
| 最近记录: |