为什么这不打印出来是真的?Visual Basic可为空值类型等于
> Dim test1 As Decimal? = Nothing
> Dim test2 As Decimal? = 5D
>
> If (test1 <> test2) Then
> Console.WriteLine("true")
> End If
为什么这不打印出来是真的?Visual Basic可为空值类型等于
> Dim test1 As Decimal? = Nothing
> Dim test2 As Decimal? = 5D
>
> If (test1 <> test2) Then
> Console.WriteLine("true")
> End If
我想通了。我需要做的
IF(不test1.Equals(测试2))
将值与空值进行比较通常会返回False
。
无法比较这些值,因为其中一个值不足,所以=
和<>
运算符将返回False
。
这是关于VB如何工作的真实声明,但在C#!=中将返回True。不协调和混乱。 – Mike
与C#中,不等于运营商,这并不工作。相反,使用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
接受你的答案,如果它是正确的。 – Yatrix