By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,814 Members | 1,671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,814 IT Pros & Developers. It's quick & easy.

OverLoad Question

P: n/a
hi all.
can i OverLoad Operators - such as Exclamation Mark "!" ?
how?

Nov 21 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
You cant in VB.NET

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"shachar" <an*******@discussions.microsoft.com> wrote in message
news:36****************************@phx.gbl...
hi all.
can i OverLoad Operators - such as Exclamation Mark "!" ?
how?

Nov 21 '05 #2

P: n/a
And by the way. You can overload operators in VS2005, however, the !
operator is not currently overloadable as per Beta1

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:ue**************@TK2MSFTNGP09.phx.gbl...
You cant in VB.NET

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"shachar" <an*******@discussions.microsoft.com> wrote in message
news:36****************************@phx.gbl...
hi all.
can i OverLoad Operators - such as Exclamation Mark "!" ?
how?


Nov 21 '05 #3

P: n/a
Visual Basic .NET 2002 & 2003 do not support operator overloading, but the
upcoming 2005 version.

"shachar" <an*******@discussions.microsoft.com> wrote in message
news:36****************************@phx.gbl...
hi all.
can i OverLoad Operators - such as Exclamation Mark "!" ?
how?
Nov 21 '05 #4

P: n/a
Yes, but 2005 ( VB.NET ) does not overload the ! operator unfortunately.

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Shiva" <sh******@online.excite.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Visual Basic .NET 2002 & 2003 do not support operator overloading, but the
upcoming 2005 version.

"shachar" <an*******@discussions.microsoft.com> wrote in message
news:36****************************@phx.gbl...
hi all.
can i OverLoad Operators - such as Exclamation Mark "!" ?
how?

Nov 21 '05 #5

P: n/a
Shachar,
The Exclamation Mark "!" operator is short hand for the default property
that accepts only a string.

http://msdn.microsoft.com/library/de...bspec9_4_1.asp

To overload it (in both VB.NET 2002 & VB.NET 2003), you simply add a Default
Property Item(key As String) to your class, something like:

Public Class MyDictionary
Inherits DictionaryBase

Default Public ReadOnly Property Item(ByVal name As String) As
MyObject
Get
Return DirectCast(Me.InnerHashtable.Item(name), MyObject)
End Get
End Property

End Class

Dim value As MyObject
Dim dictionary As MyDictionary

value = dictionary!SomeKey
As OHM suggests for other operators you need to wait for VS.NET 2005 (aka
Whidbey, due out later in 2005).

Hope this helps
Jay

"shachar" <an*******@discussions.microsoft.com> wrote in message
news:36****************************@phx.gbl...
hi all.
can i OverLoad Operators - such as Exclamation Mark "!" ?
how?

Nov 21 '05 #6

P: n/a
Thats odd, I must admit I didnt look into it to closely, except that I tried
to overload it in 2005 and it told me that this operator is not
overloadable.

Oh Well, another item learned.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uP**************@TK2MSFTNGP14.phx.gbl...
Shachar,
The Exclamation Mark "!" operator is short hand for the default property
that accepts only a string.

http://msdn.microsoft.com/library/de...bspec9_4_1.asp
To overload it (in both VB.NET 2002 & VB.NET 2003), you simply add a Default Property Item(key As String) to your class, something like:

Public Class MyDictionary
Inherits DictionaryBase

Default Public ReadOnly Property Item(ByVal name As String) As
MyObject
Get
Return DirectCast(Me.InnerHashtable.Item(name), MyObject)
End Get
End Property

End Class

Dim value As MyObject
Dim dictionary As MyDictionary

value = dictionary!SomeKey
As OHM suggests for other operators you need to wait for VS.NET 2005 (aka
Whidbey, due out later in 2005).

Hope this helps
Jay

"shachar" <an*******@discussions.microsoft.com> wrote in message
news:36****************************@phx.gbl...
hi all.
can i OverLoad Operators - such as Exclamation Mark "!" ?
how?


Nov 21 '05 #7

P: n/a
OHM,
Unfortunately the term "overload" is overloaded here ;-)

You are correct, you don't actually Overload the "!" Operator per se, as my
sample shows you actually implement a specific method, that the "!" operator
then makes use of.

If the OP actually wanted to overload the "!" operator to give it meaning
other then "dictionary member access" (which is frowned upon anyway) you
cannot do that. However I'm not sure what meaning you would give "!" as its
use is very syntax specific.

As you may know the following three lines are identical, given "Dim x As
HashTable":

y = x!abc
y = x("abc")
y = x.Item("abc")

Hope this helps
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:O1*************@TK2MSFTNGP12.phx.gbl...
Thats odd, I must admit I didnt look into it to closely, except that I
tried
to overload it in 2005 and it told me that this operator is not
overloadable.

Oh Well, another item learned.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uP**************@TK2MSFTNGP14.phx.gbl...
Shachar,
The Exclamation Mark "!" operator is short hand for the default property
that accepts only a string.

http://msdn.microsoft.com/library/de...bspec9_4_1.asp

To overload it (in both VB.NET 2002 & VB.NET 2003), you simply add a

Default
Property Item(key As String) to your class, something like:

Public Class MyDictionary
Inherits DictionaryBase

Default Public ReadOnly Property Item(ByVal name As String) As
MyObject
Get
Return DirectCast(Me.InnerHashtable.Item(name), MyObject)
End Get
End Property

End Class

Dim value As MyObject
Dim dictionary As MyDictionary

value = dictionary!SomeKey
As OHM suggests for other operators you need to wait for VS.NET 2005 (aka
Whidbey, due out later in 2005).

Hope this helps
Jay

"shachar" <an*******@discussions.microsoft.com> wrote in message
news:36****************************@phx.gbl...
> hi all.
> can i OverLoad Operators - such as Exclamation Mark "!" ?
> how?
>



Nov 21 '05 #8

P: n/a
I understand this, but its not a well known operator really.

Thanks for the tip Jay.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
OHM,
Unfortunately the term "overload" is overloaded here ;-)

You are correct, you don't actually Overload the "!" Operator per se, as my sample shows you actually implement a specific method, that the "!" operator then makes use of.

If the OP actually wanted to overload the "!" operator to give it meaning
other then "dictionary member access" (which is frowned upon anyway) you
cannot do that. However I'm not sure what meaning you would give "!" as its use is very syntax specific.

As you may know the following three lines are identical, given "Dim x As
HashTable":

y = x!abc
y = x("abc")
y = x.Item("abc")

Hope this helps
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:O1*************@TK2MSFTNGP12.phx.gbl...
Thats odd, I must admit I didnt look into it to closely, except that I
tried
to overload it in 2005 and it told me that this operator is not
overloadable.

Oh Well, another item learned.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uP**************@TK2MSFTNGP14.phx.gbl...
Shachar,
The Exclamation Mark "!" operator is short hand for the default property that accepts only a string.

http://msdn.microsoft.com/library/de...bspec9_4_1.asp

To overload it (in both VB.NET 2002 & VB.NET 2003), you simply add a

Default
Property Item(key As String) to your class, something like:

Public Class MyDictionary
Inherits DictionaryBase

Default Public ReadOnly Property Item(ByVal name As String) As
MyObject
Get
Return DirectCast(Me.InnerHashtable.Item(name), MyObject) End Get
End Property

End Class

Dim value As MyObject
Dim dictionary As MyDictionary

value = dictionary!SomeKey
As OHM suggests for other operators you need to wait for VS.NET 2005 (aka Whidbey, due out later in 2005).

Hope this helps
Jay

"shachar" <an*******@discussions.microsoft.com> wrote in message
news:36****************************@phx.gbl...
> hi all.
> can i OverLoad Operators - such as Exclamation Mark "!" ?
> how?
>



Nov 21 '05 #9

P: n/a
OHM,
but its not a well known operator really. Not well known also not widely promoted. :-)

I've remember seeing one or two places that even discourage its use,
especially in VB6 & VBA (MS Access) (links not available).

I've never really seen it promoted in VB.NET, except where I refer to it. I
find it a handy short cut. Although I am inconsistent on its use...

Paul Vick's "The Visual Basic .NET Programming Language" from Addison Wesley
has a topic on it.

If you don't have it I would recommend Paul's book, as I find Paul's book to
be a good (right size, right content) desk reference to the VB.NET language
itself. Paul's book covers just the language, not the framework.

Hope this helps
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:ut**************@tk2msftngp13.phx.gbl...I understand this, but its not a well known operator really.

Thanks for the tip Jay.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing


<<snip>>
Nov 21 '05 #10

P: n/a
Thanks

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
OHM,
but its not a well known operator really. Not well known also not widely promoted. :-)

I've remember seeing one or two places that even discourage its use,
especially in VB6 & VBA (MS Access) (links not available).

I've never really seen it promoted in VB.NET, except where I refer to it.

I find it a handy short cut. Although I am inconsistent on its use...

Paul Vick's "The Visual Basic .NET Programming Language" from Addison Wesley has a topic on it.

If you don't have it I would recommend Paul's book, as I find Paul's book to be a good (right size, right content) desk reference to the VB.NET language itself. Paul's book covers just the language, not the framework.

Hope this helps
Jay

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:ut**************@tk2msftngp13.phx.gbl...
I understand this, but its not a well known operator really.

Thanks for the tip Jay.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing


<<snip>>

Nov 21 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.