Public Class MyClass1
Private Property _myID As String
Private Property _myName As String
Private Property Y As Integer
Public Property X As Integer
Public Property myID As String
Get
Return _myID
End Get
Set(value As String)
_myID = value
End Set
End Property
Public Property myName As String
Get
Return _myName
End Get
Set(value As String)
_myName = value
End Set
End Property
Public Property mX As Interger
Get
X
End Get
Set(value As Inter)
X=2*Y
End Set
End Property
End ClassEnd Namespace
注释:这里定义为属性的意义
2 通过私有属性来访问公有属性,还可以在赋值的时候,做一些限制或者特殊的处理,计算。达到对私有属性更高一层的控制。某一个属性的值改变了,自动触发另外一个属性的值。不用在外部通过事件的代码来实现。
原文链接:https://www.f2er.com/vb/258381.html