我记得教授告诉他以下是不好的做法.但它使得逐步执行代码变得不那么繁琐.我只是在征求关于利弊的评论: Friend Class MyClass Private isEmpty As Boolean Public Property IsEmpty() As Boolean Get Return
Friend Class MyClass Private isEmpty As Boolean Public Property IsEmpty() As Boolean Get Return isEmpty End Get Set(ByVal Value As Integer) isEmpty = value End Set End Property Public Sub MyMethod() ''//Is this more correct: If Me.IsEmpty() Then ''//Do something. End If ''//Is this bad practice?: If isEmpty Then ''//Do something. End If End Sub End Class如果你已经设置了一个属性来访问私有成员变量“isEmpty”,那么我会使用类本身内部的属性,除非有一个很好的理由不这样做.
原因是您可能在以后的某个时间点需要在设置属性时(或者可能在检索时)执行更多工作,然后您可能必须在类中找到对私有成员变量的所有引用并更改他们改为访问该物业.