TypeOf someobject IsNot TypeOfObject

Now VB has an IsNot operator, though it isn't quite complete:
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...

[608 byte] By [RolfBjarne] at [2008-1-10]
# 1
Make sure you only use on ref Types. For Example:


'this will work
Dim yourVar As New Object

'returns False
If TypeOf yourVar IsNot Object Then
'code here
End If

'this won't work
Dim yourVar As Integer

'error
If TypeOf yourVar IsNot Integer Then
'code here
End If


JoeSmugeresky at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
Is it possible if you box the value type?
GaryD at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

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.

RolfBjarne at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

If you are looking at replacing the

If Not TypeOf (y) Is Obj1 Then

with something like

If TypeOf (y) Isnot Obj1 Then
Then this is not going to be in whidbey.

The 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.

spotty at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5
The thing is that "typeof ... is" is a single operator - the "is" in there is not related to the "is" operator. As such, when the IsNot operator was introduced, it did not affect other syntaxes that use the text "is", such as the typeof...is operator or the "case is" statement.

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.

AlexMoura at 2007-8-21 > top of Msdn Tech,Visual Basic,Visual Basic Language...