【发布时间】:2011-03-13 03:43:14
【问题描述】:
为对象定义属性而不是直接访问私有变量有什么好处?
代替:
public class A
private _x as integer = 0
Public property X() as integer
Get
return _x
End Get
Set(ByVal value As integer)
_x = value
End Set
End Property
end class
为什么我们不能做以下事情:
public class A
public _x as integer = 0
end class
有什么好处?
【问题讨论】:
-
:) 是的,我也发现它是重复的……无论如何,谢谢指点它
标签: c# class variables properties field