Friday, 15 May 2015

Testing if an Object is Nothing/null in VB.NET vs C# -



Testing if an Object is Nothing/null in VB.NET vs C# -

i'm converting c# code vb.net. have simple dictionary-like info construction contains name/value pairs. value element of type object. c# code looks this

if(x.value != null) // 1: store x.value in database else // sore dbnull.value in database

as expected, if x.value happens boolean of value false, code block 1 above executes.

however, equivalent vb.net code fall through else block on boolean of false

if x.value not nil ' store x.value in database else ' land here if x.value boolean value of false , incorrectly store dbnull.value in database endif

vb apparently thinks boolean false value equivalent nothing. i'll maintain comments vb myself, there non-convoluted way, i.e. without using reflection, work around problem?

edit: original vb code actually

if x.value <> nil

that worked described.

if x.value isnot nil

works correctly. steve.

use if x.value dbnull.value ...

c#-to-vb.net

No comments:

Post a Comment