IIf
Value = IIf ( Test AS Boolean , TrueExpression , FalseExpression )
Value = If ( Test AS Boolean , TrueExpression , FalseExpression )
评估
Test 表达式,如果为真(
TRUE)返回
TrueExpression ,如果为假(
FALSE)返回
FalseExpression 。
注意!
与
IF语句或者C/Perl的=?操作相反,无论
Test 的值是什么,
TrueExpression 和
FalseExpression 都被评估。
示例
Dim X As Integer = 7
PRINT If((X MOD 2) = 0, "even", "odd")
' Never do the following in real code, because it is not translatable!
Dim X As Integer = 7
PRINT "You have " & X & " message" & If(X <> 1, "s", "") & " waiting."
You have 7 messages waiting.
Dim X As Integer = 7
PRINT If((X MOD 2) = 1, "odd", 1 / 0)
参见