Jump to content

IsNot Nothing and Not Is Nothing

- - - - -

  • Please log in to reply
3 replies to this topic

#1
wwarren

wwarren

    Learning Programmer

  • Members
  • PipPipPip
  • 60 posts
Is there a difference (performance wise) between these two statements?

If x IsNot Nothing Then

    'Do Something

End If

and

If Not x Is Nothing Then

    'Do Something

End If

In VB.NET?

#2
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 405 posts
Generally speaking (applying to all languages), !(Expression) is a u nary operator whose evaluation should be faster than a binary operator i.e.

Assuming A and B are two simple variables:

!A (Takes only one memory fetch operation for value of variable A and takes the compliment)
A != B (Takes two memory fetch operations and then compares there values)

Hence !A is faster.

#3
wwarren

wwarren

    Learning Programmer

  • Members
  • PipPipPip
  • 60 posts
So it would be the second one of my examples?

#4
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 405 posts
Yes




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users