OverLoad Question

  • Thread starter Thread starter shachar
  • Start date Start date
S

shachar

hi all.
can i OverLoad Operators - such as Exclamation Mark "!" ?
how?
 
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
 
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
 
Visual Basic .NET 2002 & 2003 do not support operator overloading, but the
upcoming 2005 version.

hi all.
can i OverLoad Operators - such as Exclamation Mark "!" ?
how?
 
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
 
Shachar,
The Exclamation Mark "!" operator is short hand for the default property
that accepts only a string.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbls7/html/vblrfvbspec9_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
 
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
 
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
 
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
 
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 ) said:
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>>
 
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
 

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

Back
Top