TypeOf someobject IsNot TypeOfObject
I cannot write
TypeOfsomeobjectIsNot TypeOfObject
Any plans to implement this? I find myself writing it every now and then but then I have to change it...
TypeOfsomeobjectIsNot TypeOfObject
Any plans to implement this? I find myself writing it every now and then but then I have to change it...
'this will work 'returns False 'this won't work 'error |
It has nothing to do with ref / value types:
Dim i as Object If TypeOf i IsNot Object Then DoSomething() End If |
This does not compile. It gives two errors:
-"BC30224: 'Is' expected." squiggling "IsNot"
-"BC30109: 'System.Object' is a class type and cannot be used as an expression." squiggling "Object".
If I rewrite to:
Dim i as Object If Not TypeOf i Is Object Then DoSomething() End If |
This compiles perfectly.
If
Not TypeOf (y) Is Obj1 ThenThe IsNot operator determines whether two object references refer to different objects. It compares the pointer values of reference types and is meaningless with value types.
The Is operator however can also be used with the TypeOf keyword to make a TypeOf...Is expression, which tests whether an object variable is compatible with a data type.
So you'll just have to stick with
If Not TypeOf (y) Is Obj1 Then
for the time being.
Changes have been considered to make the syntax a bit more coherent along other is usages, but it was decided not to make them in VB 2005. They might be considered for the next version.