Why is there a difference in checking null against a value in VB.NET and C#?

前端 未结 7 1722
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 19:02

In VB.NET this happens:

Dim x As System.Nullable(Of Decimal) = Nothing
Dim y As System.Nullable(Of Decimal) = Nothing
         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 19:20

    Your VB code is simply incorrect - if you change the "x <> y" to "x = y" you will still have "false" as the result. The most common way of expression this for nullable instances is "Not x.Equals(y)", and this will yield the same behavior as "x != y" in C#.

提交回复
热议问题