为什么未声明的带下划线的变量不会给出调试错误
Why does a underscored variable that is not declared not give an debug error
这段代码在VS 2017 (15.9.5)中没有给出编译错误?
为什么会这样?
Class BugInclass
Public Property myProp As String
Public Sub MyFct()
myProp = _myProp
End Sub
End Class
请注意,“_myProp”并未贴标 - 它只是被视为 "myProp"。
您正在使用 auto-property,它们只是语法糖。你写这段代码:
Public Property myProp As String
但实际编译的是这样的:
Private _myProp As String
Public Property myProp As String
Get
Return _myProp
End Get
Set
_myProp = value
End Set
End Property
第二个片段是几年前我们必须为所有属性编写的内容。 auto-property 更方便,但旧的、冗长的代码仍然存在于幕后,因此隐式支持字段仍然存在。
这段代码在VS 2017 (15.9.5)中没有给出编译错误?
为什么会这样?
Class BugInclass
Public Property myProp As String
Public Sub MyFct()
myProp = _myProp
End Sub
End Class
请注意,“_myProp”并未贴标 - 它只是被视为 "myProp"。
您正在使用 auto-property,它们只是语法糖。你写这段代码:
Public Property myProp As String
但实际编译的是这样的:
Private _myProp As String
Public Property myProp As String
Get
Return _myProp
End Get
Set
_myProp = value
End Set
End Property
第二个片段是几年前我们必须为所有属性编写的内容。 auto-property 更方便,但旧的、冗长的代码仍然存在于幕后,因此隐式支持字段仍然存在。