为什么这不打印出来?
> Dim test1 As Decimal? = Nothing
> Dim test2 As Decimal? = 5D
>
> If (test1 <> test2) Then
> Console.WriteLine("true")
> End If
答案 0 :(得分:4)
与C#不同,not equals运算符不适用于此。相反,请使用Nullabe.Equals()
Dim test1 As Decimal? = Nothing
Dim test2 As Decimal? = 5D
If (Nullable.Equals(test1, test2) = False) Then
Console.WriteLine("not equal")
Else
Console.WriteLine("equal")
End If
答案 1 :(得分:0)
将值与空值进行比较通常会返回False
。
无法比较值,因为缺少值,因此=
和<>
运算符都会返回False
。
答案 2 :(得分:0)
IF(不是test1.Equals(test2))