468,544 Members | 1,738 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,544 developers. It's quick & easy.

If Typeof X IsNot Y Then...

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

Nov 21 '05 #1
11 5353
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/lib...US,VS.80).aspx
http://msdn2.microsoft.com/en-us/lib...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/lib...US,VS.80).aspx
--
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Jason Kendall" <Ja**********@hotmail.com> wrote in message
news:3o********************************@4ax.com...
| Why doesn't the new "IsNot" operator work in conjunction with
| 'Typeof'?
|
Nov 21 '05 #2
"The "Is" in the TypeOf operator is a placeholder"

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

Thanks.

--
Jason Kendall
Ja**********@hotmail.com

On Fri, 21 Oct 2005 10:33:08 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja************@tsbradley.net> 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/lib...US,VS.80).aspx
http://msdn2.microsoft.com/en-us/lib...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/lib...US,VS.80).aspx

Nov 21 '05 #3

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/lib...US,VS.80).aspx
http://msdn2.microsoft.com/en-us/lib...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

Nov 21 '05 #4
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
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
|
| 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/lib...US,VS.80).aspx
| > http://msdn2.microsoft.com/en-us/lib...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
|
Nov 21 '05 #5
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
"Jason Kendall" <Ja**********@hotmail.com> wrote in message
news:mb********************************@4ax.com...
| "The "Is" in the TypeOf operator is a placeholder"
|
| How very strange. That clears up why 'TypeOf' doesn't use
| parenthesis.
|
| Thanks.
|
| --
| Jason Kendall
| Ja**********@hotmail.com
|
|
|
| On Fri, 21 Oct 2005 10:33:08 -0500, "Jay B. Harlow [MVP - Outlook]"
| <Ja************@tsbradley.net> 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/lib...US,VS.80).aspx
| >http://msdn2.microsoft.com/en-us/lib...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/lib...US,VS.80).aspx
Nov 21 '05 #6
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

"Larry Lard" wrote:


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

--
Larry Lard
Replies to group please

Nov 21 '05 #7
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
"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> wrote in
message news:u6**************@tk2msftngp13.phx.gbl...
| 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
|
|
| "Jason Kendall" <Ja**********@hotmail.com> wrote in message
| news:mb********************************@4ax.com...
|| "The "Is" in the TypeOf operator is a placeholder"
||
|| How very strange. That clears up why 'TypeOf' doesn't use
|| parenthesis.
||
|| Thanks.
||
|| --
|| Jason Kendall
|| Ja**********@hotmail.com
||
||
||
|| On Fri, 21 Oct 2005 10:33:08 -0500, "Jay B. Harlow [MVP - Outlook]"
|| <Ja************@tsbradley.net> 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/lib...US,VS.80).aspx
|| >http://msdn2.microsoft.com/en-us/lib...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/lib...US,VS.80).aspx
|
|
Nov 21 '05 #8

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

Nov 21 '05 #9
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
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
|
| 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
|
Nov 21 '05 #10
Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> schrieb:
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/>
Nov 21 '05 #11
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
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ep*************@TK2MSFTNGP10.phx.gbl...
| Jay,
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> schrieb:
| > 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/>
Nov 21 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Robert Mark Bram | last post: by
3 posts views Thread by Alberto | last post: by
7 posts views Thread by Leon | last post: by
1 post views Thread by Brien King | last post: by
9 posts views Thread by Klaus Johannes Rusch | last post: by
20 posts views Thread by rkk | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.