Does anyone here use VB.NET and have a strong preference for or against using IsNothing
as opposed to Is Nothing
(for example, If IsNothing(anObject)
or If anObject Is Nothing...
)? If so, why?
EDIT: If you think they're both equally acceptable, do you think it's best to pick one and stick with it, or is it OK to mix them?
I also tend to use the Is Nothing version partially from using it as much as I do in SQL.
Is Nothing requires an object that has been assigned to the value Nothing. IsNothing() can take any variable that has not been initialized, including of numeric type. This is useful for example when testing if an optional parameter has been passed.
I initially used IsNothing but I've been moving towards using Is Nothing in newer projects, mainly for readability. The only time I stick with IsNothing is if I'm maintaining code where that's used throughout and I want to stay consistent.