开发者

Using two equals signs in Visual Basic 2008

开发者 https://www.devze.com 2023-02-10 11:12 出处:网络
In code, why wouldn\'t this work?开发者_开发百科 intMax = intTopValue = 20 This is interpreted as intMax = (intTopValue = 20).

In code, why wouldn't this work?

开发者_开发百科
intMax = intTopValue = 20


This is interpreted as intMax = (intTopValue = 20).

intTopValue = 20 will check whether intTopValue is equal to 20 and return true or false.
This boolean will then be assigned to intMax.

Most languages don't have this issue, since they use separate operators for assignment (= or :=) and equality (== or =).

By contrast, VB shares = for both operations. Therefore, when a = b is written as an expression, it always means equality.

0

精彩评论

暂无评论...
验证码 换一张
取 消