"Not ... Is Nothing" versus "... IsNot Nothing"

foo IsNot Nothing

The following line is straight from Microsoft's Visual Basic Coding Conventions:

Use the IsNot keyword instead of Not...Is Nothing.


I would go with the first variant - it reads like English and is easier to follow/understand than the second one. Other than that, they are equivalent.


I found a similar question here VB.NET - IsNothing versus Is Nothing, where I feel this question was exhaustively answered. Among the answers Jack Snipes identified http://weblogs.asp.net/psteele/410336, a blog that gives some extra detail. From those I prefer and have used

IsNot Nothing

which also makes my code easier to read and understand.


The

If Not var1 Is Nothing Then

Is a hangover from VB6. There didn't used to be an IsNot, and so this was the only way to determine if a variable was not Nothing. It seems to be redundant in VB.NET.

Tags:

Vb.Net

Nothing