Tuesday, May 18, 2010

"IsNothing" vs "Is Nothing"

People have found using "is nothing" more readable and object oriented. If we talk about the performance, you should look at the disassembled code and you would find that "Is Nothing" internally uses inbuilt function "IsNothing" that means that direct function call would be little bit faster.
If you are making the use of one over other as a practice then you should also think of when you use them during negation, what would you prefer
"not isnothing(myobj)" or "isnot myobj nothing"

IsNothing function being a VB function is not type safe, so if  you pass a value type to this function, the value type will automatically be boxed and evaluated. If you check value type against "is nothing" statement then it will throw runtime error.

Conclusion: IsNothing might be preferable if you have come from VB background and want to write defensive code. But if you are worried of type safety, use "Is Nothing".

Reference: http://bytes.com/topic/visual-basic-net/answers/352342-isnothing-vs-nothing

Hope this helps!!

No comments:

Post a Comment