If Typeof X IsNot Y Then...

J

Jay B. Harlow [MVP - Outlook]

Jason,
IMHO:

Because IsNot is the inverse of the Is operator. They are both used to
compare object references.

http://msdn2.microsoft.com/en-us/library/kb136x1y(en-US,VS.80).aspx
http://msdn2.microsoft.com/en-us/library/t3bat82c(en-US,VS.80).aspx

The "Is" in the TypeOf operator is a placeholder & not the operator per se.
The TypeOf operator is used to check the data type of an object reference.

http://msdn2.microsoft.com/en-us/library/0ec5kw18(en-US,VS.80).aspx


--
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Why doesn't the new "IsNot" operator work in conjunction with
| 'Typeof'?
|
 
J

Jason Kendall

"The "Is" in the TypeOf operator is a placeholder"

How very strange. That clears up why 'TypeOf' doesn't use
parenthesis.

Thanks.
 
J

Jay B. Harlow [MVP - Outlook]

Larry,
| So the 'Is' in 'TypeOf X Is T' 'IsNot' the 'Is' in 'X Is Y' ? :)

By jove I think he's got it. ;-)

--
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


|
| Jay B. Harlow [MVP - Outlook] wrote:
| > Jason,
| > IMHO:
| >
| > Because IsNot is the inverse of the Is operator. They are both used to
| > compare object references.
| >
| > http://msdn2.microsoft.com/en-us/library/kb136x1y(en-US,VS.80).aspx
| > http://msdn2.microsoft.com/en-us/library/t3bat82c(en-US,VS.80).aspx
| >
| > The "Is" in the TypeOf operator is a placeholder & not the operator per
se.
|
| So the 'Is' in 'TypeOf X Is T' 'IsNot' the 'Is' in 'X Is Y' ? :)
|
| --
| Larry Lard
| Replies to group please
|
 
J

Jay B. Harlow [MVP - Outlook]

Jason,
| How very strange. That clears up why 'TypeOf' doesn't use
| parenthesis.
Yea its strange, I think parenthesis would "complicate" the TypeOf syntax
unnecessarily as:

If TypeOf(anObject) Is Something Then

Is miss-leading, it too close to GetType. TypeOf "IsNot" GetType!

If TypeOf anObject Is Something Then

is different then:

If GetType(anObject) Is Something Then

Remember GetType(anObject) returns a specific type & checks to see if o is
specifically Something, where as TypeOf allows derived types & interfaces to
also match. For example:

Class Something
...
End Class

Class SomethingSpecific
Inherits Something
...
End Class

Dim anObject As Object
' anObject = New Something
' anObject = New SomethingSpecific

If TypeOf anObject Is Something Then
' both Something & SomethingSpecific match
End If

If GetType(anObject) Is Something Then
' only Something matches
End If

I suppose they could have implemented TypeOf as a function similar to CType
& DirectCast:

If TypeOf(anObject, Something) Then

IMHO However that doesn't read as well.

--
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| "The "Is" in the TypeOf operator is a placeholder"
|
| How very strange. That clears up why 'TypeOf' doesn't use
| parenthesis.
|
| Thanks.
|
| --
| Jason Kendall
| (e-mail address removed)
|
|
|
| On Fri, 21 Oct 2005 10:33:08 -0500, "Jay B. Harlow [MVP - Outlook]"
|
| >Jason,
| >IMHO:
| >
| >Because IsNot is the inverse of the Is operator. They are both used to
| >compare object references.
| >
| >http://msdn2.microsoft.com/en-us/library/kb136x1y(en-US,VS.80).aspx
| >http://msdn2.microsoft.com/en-us/library/t3bat82c(en-US,VS.80).aspx
| >
| >The "Is" in the TypeOf operator is a placeholder & not the operator per
se.
| >The TypeOf operator is used to check the data type of an object
reference.
| >
| >http://msdn2.microsoft.com/en-us/library/0ec5kw18(en-US,VS.80).aspx
 
G

Guest

Larry,

I guess it really does depend on what the meaning of the word is is!

By the way, another place that Is is used strangely in the BASIC-style
languages is its use in the Case clause of a Select Case statement, when
using relational operators. For example:

Case Is > 12

I hate the fact that Is shows up there.

Kerry Moorman
 
J

Jay B. Harlow [MVP - Outlook]

Doh!
| If TypeOf(anObject, Something) Then
|
| IMHO However that doesn't read as well.

They could have used IsTypeOf

If IsTypeOf(anObject, Something) Then

Although it reads better then the above, I still prefer the TypeOf operator
as is...

--
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


message | Jason,
|| How very strange. That clears up why 'TypeOf' doesn't use
|| parenthesis.
| Yea its strange, I think parenthesis would "complicate" the TypeOf syntax
| unnecessarily as:
|
| If TypeOf(anObject) Is Something Then
|
| Is miss-leading, it too close to GetType. TypeOf "IsNot" GetType!
|
| If TypeOf anObject Is Something Then
|
| is different then:
|
| If GetType(anObject) Is Something Then
|
| Remember GetType(anObject) returns a specific type & checks to see if o is
| specifically Something, where as TypeOf allows derived types & interfaces
to
| also match. For example:
|
| Class Something
| ...
| End Class
|
| Class SomethingSpecific
| Inherits Something
| ...
| End Class
|
| Dim anObject As Object
| ' anObject = New Something
| ' anObject = New SomethingSpecific
|
| If TypeOf anObject Is Something Then
| ' both Something & SomethingSpecific match
| End If
|
| If GetType(anObject) Is Something Then
| ' only Something matches
| End If
|
| I suppose they could have implemented TypeOf as a function similar to
CType
| & DirectCast:
|
| If TypeOf(anObject, Something) Then
|
| IMHO However that doesn't read as well.
|
| --
| Jay [MVP - Outlook]
| .NET Application Architect, Enthusiast, & Evangelist
| T.S. Bradley - http://www.tsbradley.net
|
|
| || "The "Is" in the TypeOf operator is a placeholder"
||
|| How very strange. That clears up why 'TypeOf' doesn't use
|| parenthesis.
||
|| Thanks.
||
|| --
|| Jason Kendall
|| (e-mail address removed)
||
||
||
|| On Fri, 21 Oct 2005 10:33:08 -0500, "Jay B. Harlow [MVP - Outlook]"
||
|| >Jason,
|| >IMHO:
|| >
|| >Because IsNot is the inverse of the Is operator. They are both used to
|| >compare object references.
|| >
|| >http://msdn2.microsoft.com/en-us/library/kb136x1y(en-US,VS.80).aspx
|| >http://msdn2.microsoft.com/en-us/library/t3bat82c(en-US,VS.80).aspx
|| >
|| >The "Is" in the TypeOf operator is a placeholder & not the operator per
| se.
|| >The TypeOf operator is used to check the data type of an object
| reference.
|| >
|| >http://msdn2.microsoft.com/en-us/library/0ec5kw18(en-US,VS.80).aspx
|
|
 
L

Larry Lard

Jay said:
They could have used IsTypeOf

If IsTypeOf(anObject, Something) Then

Although it reads better then the above, I still prefer the TypeOf operator
as is...

How about

If anObject IsA Something Then

reinforcing the "is-a" idea you get in all the OO texts?
 
J

Jay B. Harlow [MVP - Outlook]

Larry,
I like IsA as a replacement for TypeOf Is!

My only concern, albeit minor, is would a quick glance of the code cause
confusion with the Is operator?

Or would one include IsA with TypeOf?

If TypeOf anObject IsA Something Then

Which would elimate the OP's question in the first place ;-)

Either way I like the IsA operator.

--
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


|
| Jay B. Harlow [MVP - Outlook] wrote:
| > They could have used IsTypeOf
| >
| > If IsTypeOf(anObject, Something) Then
| >
| > Although it reads better then the above, I still prefer the TypeOf
operator
| > as is...
|
| How about
|
| If anObject IsA Something Then
|
| reinforcing the "is-a" idea you get in all the OO texts?
|
| --
| Larry Lard
| Replies to group please
|
 
H

Herfried K. Wagner [MVP]

Jay,

Jay B. Harlow said:
Or would one include IsA with TypeOf?

If TypeOf anObject IsA Something Then

Which would elimate the OP's question in the first place ;-)

Either way I like the IsA operator.

.... there must be an 'IsAn' operator too:

\\\
If Person IsAn Employee Then
...
End If
///

SCNR
 
J

Jay B. Harlow [MVP - Outlook]

Herfried,
| > Either way I like the IsA operator.
| ... there must be an 'IsAn' operator too:
*Chuckles*

I was actually thinking the same thing when I responded ;-)

--
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Jay,
|
| > Or would one include IsA with TypeOf?
| >
| > If TypeOf anObject IsA Something Then
| >
| > Which would elimate the OP's question in the first place ;-)
| >
| > Either way I like the IsA operator.
|
| ... there must be an 'IsAn' operator too:
|
| \\\
| If Person IsAn Employee Then
| ...
| End If
| ///
|
| SCNR
|
| --
| M S Herfried K. Wagner
| M V P <URL:http://dotnet.mvps.org/>
| V B <URL:http://classicvb.org/petition/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top