Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在快速从其他地方复制代码。经过测试和调试,我不断得到非常奇怪的结果。再次比较代码后,我意识到我在=等式中添加了一个额外的内容:
=
Dim lowerLeft As Integer = x = +y * terrainWidth
与此相反:
Dim lowerLeft As Integer = x + y * terrainWidth
这实际上是在做什么?
如果你有Option Strict On(而且你应该),这不会编译。
Option Strict On
表达式内部的A=是比较运算符。其结果是Boolean. 在您的情况下,这意味着表达式等效于:
Boolean
Dim lowerLeft As Integer If x = +y * terrainWidth Then lowerLeft = True ' Converted to 1 Else lowerLeft = False ' Converted to 0 End If
Option Strict On正确地禁止这种隐式转换。