Thursday, May 29, 2008

Not xxx Is Nothing and xxx IsNot Nothing in VB.NET

It took me a while to figure that that you can say:

If var1 IsNot Nothing Then
...
End If


Instead of the awkward:

If Not var1 is Nothing Then
...
End If

Of course the IsNot is like the Is and will work with when comparing any two object references, not just for testing for Nothing.

8 comments:

Dan said...

Exactly what I was looking for. Thanks.

Michael Ma said...

thanks for sharing this.

Anonymous said...

Thanks that was a big help!!

Eduardo Souto Vidal said...

Perfectttt explanation!!! THANKS!

Eduardo Souto Vidal said...

Perfect explanation! THANKS

Anonymous said...

Thanks, appreciated. "If Not X Is Nothing" is kind of a clunky way of writing things!:)

"If X IsNot Nothing" is much better.

Umi said...

Nice information


Free Auto typing, I hope you like it
http://sourcecode-world.blogspot.com/

Anonymous said...

thanks have been searching for this. SUPER USEFUL!!