Class Person
Public Age As Integer
Public Sub PrintAge()
HttpContext.Current.Response.Write(Age)
End Sub
End Class
还有一个就是用属性
Class Person
Private _Age As Integer
Public Property Age() As Integer
Get
Return (Me._Age)
End Get
Set(ByVal value As Integer)
Me._Age = value
End Set
End Property
Public Sub PrintAge()
HttpContext.Current.Response.Write(Me._Age)
End Sub
End Class
在外面都可以用:
Dim student As Person = New Person()
student.Age = 10
student.PrintAge
输出的结果一样。两者,除了property可以控制ReadOnly和WriteOnly,从执行性能或物理格式上是不是有区别?