473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

OverLoad Question

hi all.
can i OverLoad Operators - such as Exclamation Mark "!" ?
how?

Nov 21 '05 #1
10 2187
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: bsaucer | last post by:
I am creating a class with operator overloads. It makes references to another class I've created, but do not wish to modify. I try to overload an operator having arguments having the other class...
9
by: Mario Charest | last post by:
.. Hi, It's possible to overload the operator, but I wonder if it's possible to somehow overload and so forth. My goal would be to switch from static array declaration into something...
6
by: Hunter Hou | last post by:
Hi, I have this program, compiling is passed, but when i wanted to get the executable file(g++ -o output input.o), it fails. Who can lead me where the error is? Thanks, Hunter ===
13
by: Tony Johansson | last post by:
Hello! I just wonder if it's possible to overload a method only by having a different return type. //Tony
17
by: Chris | last post by:
To me, this seems rather redundant. The compiler requires that if you overload the == operator, you must also overload the != operator. All I do for the != operator is something like this: ...
3
by: needin4mation | last post by:
The code is taken from the book Professional C#: abstract class GenericCustomer { private string name; public GenericCustomer(string name) { this.name = name; }...
1
by: bhavin | last post by:
it is possible to overload new and delete operator but why is it needed to overload new and delete this question is asked by my professor so please any body reply to this question,also explain in a...
5
by: richard.parker | last post by:
Hello, I need to overload operator new with affecting the system libraries. Has anyone done this? I've got 2 static libraries and application source code where the operator needs to be...
1
by: v4vijayakumar | last post by:
When (at which phase of the software development) the decision would usually be taken to overload operators? Will you first design with functions and then move these functionalities to overloaded...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.