1

I am quite surprised that in C#:

int? a = null;
int? b = null;
intc = a == b; //c = true

While in VB:

Dim a As Integer? = Nothing
Dim b As Integer? = Nothing

if( a = b ) generates an exception because the condition a = b is apparently resolved to Nothing (instead of true in C#)

I suppose I can change my condition to: if( (a Is Nothing AndAlso b Is Nothing) OrElse a = b) but I find this ugly! Is there a more elegant way of writing this so simple condition?

A.D.
  • 1,062
  • 1
  • 13
  • 37
  • 1
    In short: in VB.NET it has sql meaning: `Nothing` means "unknown", if you compare an unknown value `a` with an unknown value `b` the result is: _unknown_ so `Nothing`. In C# two `null`s are `equal`. – Tim Schmelter Jan 30 '19 at 11:38

0 Answers0