I'm converting some C# code to VB.NET. I have a simple dictionary-like data structure that contains name/value pairs. The value element is of type Object. My C# code looks like this
if(x.Value != null)
// 1: Store x.Value in database
else
// Sore DBNULL.Value in database
As expected, if x.Value happens to be a boolean of value false, code block 1 above executes.
However, the equivalent VB.NET code will fall through to the else block on a Boolean of False
If x.Value Is Not Nothing Then
' Store x.Value in database
Else
' We land here if x.Value is a Boolean with a value of False and incorrectly store DBNULL.Value in database
EndIF
VB apparently thinks a Boolean with a False value is equivalent to Nothing. I'll keep my comments about VB to myself, but is there a non-convoluted way, i.e. without using reflection, to work around this problem?
Edit: my original VB code was actually
If x.Value <> Nothing
That worked as described.
If x.Value IsNot Nothing
works correctly. Thanks Steve.