在VS 2017 VB.Net中,调试器发现错误时会在错误的行停止。但是不一致,也不与行尾不一致有关。该行为很奇怪,因为到目前为止,我发现它似乎只影响对象和字符串数组,而其他引起错误的数组则可以正确识别。创建带有一些按钮的表单,在此示例中,我使用了4。输入以下代码作为按钮处理程序。请注意,除了数组类型之外,每个处理程序中的代码都是相同的。调试器将在错误的行停止,但仅在具有对象和字符串数组的处理程序中停止。它停在有错误的那一行之后。我环顾四周,看到了行尾不一致的解决方案,但是VS并没有抱怨,这是一个全新的项目,除了下面看到的代码之外,没有其他代码,即使行尾不一致,调试器为什么也应该只为我误导我某种类型?今天早上,我花了几个小时在错误的阵列中寻找一个不存在的错误。干杯。
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myArray(1) As Integer 'Note: INTEGER ok
myArray(1) = 0 'This line is valid and executes ok
myArray(2) = 0 'This line is correctly identified as an out of bounds error
myArray(1) = 0
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim myArray(1) As Object ' Note: OBJECT not ok
myArray(1) = 0 'This line is valid and executes ok
myArray(2) = 0 'This Line should show as an out of bounds error but it doesn't
myArray(1) = 0 'This line is still valid but is now incorrectly identified as the error line
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim myArray(1) As Double 'Note: DOUBLE ok
myArray(1) = 0 'This line is valid and executes ok
myArray(2) = 0 'This line is correctly identified as an out of bounds error
myArray(1) = 0
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim myArray(1) As String ' Note: STRING not ok
myArray(1) = 0 'This line is valid and executes ok
myArray(2) = 0 'This Line should show as an out of bounds error but it doesn't
myArray(1) = 0 'This line is still valid but is now incorrectly identified as the error line
End Sub
End Class