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

Operators do not work in VB.NET with a C# referenced assembly

P: n/a
Unfortunately due to project constraints I have to code in VB.NET of
which I have little experience with. I have a C# assembly referenced
which contains an object where the + and - operators have been
successfully overridden and in my other C# projects the following code
(changed for posting) compiles and works:

Field TheField = this.GetField(1);
TheField += this.GetField(2);
Etc...

When I attempt to do something similar in VB.NET I get the following
compiler error "Operator '+' is not defined for types 'Field' and
'Field'"
I've tried different variations of the code with no joy - can
anyone assist and tell me what I am doing wrong?

Dim TheField As Field = Me.GetField(1)
TheField += Me.GetField(2)
TheField = (TheField + me.GetField(3))

Thanks in advance

Mar 30 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
VB.NET (at least in 1.1, not sure about 2.0) doesn't support operator
overloading.

So, to use it, you would have to call the methods that are generated that
represent the operators. If you use intellisense, you should be able to
find them. There is a naming convention for them (which unfortunately I
don't remember), but it would have the operator name in it. But in the end,
you would have to call a method, you wouldn't be able to use the operators.

<mk*****@hotmail.com> wrote in message
news:11********************@e56g2000cwe.googlegrou ps.com...
Unfortunately due to project constraints I have to code in VB.NET of
which I have little experience with. I have a C# assembly referenced
which contains an object where the + and - operators have been
successfully overridden and in my other C# projects the following code
(changed for posting) compiles and works:

Field TheField = this.GetField(1);
TheField += this.GetField(2);
Etc...

When I attempt to do something similar in VB.NET I get the following
compiler error "Operator '+' is not defined for types 'Field' and
'Field'"
I've tried different variations of the code with no joy - can
anyone assist and tell me what I am doing wrong?

Dim TheField As Field = Me.GetField(1)
TheField += Me.GetField(2)
TheField = (TheField + me.GetField(3))

Thanks in advance

Mar 30 '06 #2

P: n/a
Actually behing the scene .NET creates a method named "opp_add" (if I
remember). In VB.NET 2003, you have to call explicitely this method (is this
what you are using, I believe VB 2005 does this for you automatically when
the operator is used).

--
Patrice

<mk*****@hotmail.com> a écrit dans le message de news:
11********************@e56g2000cwe.googlegroups.co m...
Unfortunately due to project constraints I have to code in VB.NET of
which I have little experience with. I have a C# assembly referenced
which contains an object where the + and - operators have been
successfully overridden and in my other C# projects the following code
(changed for posting) compiles and works:

Field TheField = this.GetField(1);
TheField += this.GetField(2);
Etc...

When I attempt to do something similar in VB.NET I get the following
compiler error "Operator '+' is not defined for types 'Field' and
'Field'"
I've tried different variations of the code with no joy - can
anyone assist and tell me what I am doing wrong?

Dim TheField As Field = Me.GetField(1)
TheField += Me.GetField(2)
TheField = (TheField + me.GetField(3))

Thanks in advance

Mar 30 '06 #3

P: n/a
The generated method is called op_Addition.

In 2003 you must use this method:
Field1 = Field.op_Addition(Field2, Field3)

In 2005 you can use + just as in C#.:
Field1 = Field2 + Field3
/claes
"Patrice" <a@bc.c> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
Actually behing the scene .NET creates a method named "opp_add" (if I
remember). In VB.NET 2003, you have to call explicitely this method (is
this what you are using, I believe VB 2005 does this for you automatically
when the operator is used).

--
Patrice

<mk*****@hotmail.com> a écrit dans le message de news:
11********************@e56g2000cwe.googlegroups.co m...
Unfortunately due to project constraints I have to code in VB.NET of
which I have little experience with. I have a C# assembly referenced
which contains an object where the + and - operators have been
successfully overridden and in my other C# projects the following code
(changed for posting) compiles and works:

Field TheField = this.GetField(1);
TheField += this.GetField(2);
Etc...

When I attempt to do something similar in VB.NET I get the following
compiler error "Operator '+' is not defined for types 'Field' and
'Field'"
I've tried different variations of the code with no joy - can
anyone assist and tell me what I am doing wrong?

Dim TheField As Field = Me.GetField(1)
TheField += Me.GetField(2)
TheField = (TheField + me.GetField(3))

Thanks in advance


Mar 30 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.