【发布时间】:2011-01-17 19:34:59
【问题描述】:
这可能是一个非常基本(没有双关语)的问题,但我似乎无法在任何地方找到答案。为什么func1的结果返回False而func2返回True?在我所做的所有其他测试中,整数 1 被转换为布尔值 true,0 被转换为 false。如果我将 rtnValue 设置为 1 或 0,则可以正常工作。
Public Function func1() As Boolean
Dim rtnValue As Integer = 0
Return rtnValue = 1
End Function
Public Function func2() As Boolean
Dim rtnValue As Integer = 0
Return rtnValue = 0
End Function
【问题讨论】:
-
= 运算符既可以在赋值语句中使用,也可以在表达式中用作相等运算符。您正在获取表达式版本。 1 = 0 为假。
标签: vb.net