Technical Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to overload operators in vb.net?

Is it possible to do programmer defined boxing on byvalue
variables in vb.net?
 
No and no. VB does not support this.

If you need this capability, I recommend you use C#.
 
Bill,
You will need to wait for VB.NET 2004 (Whidbey) to get overloaded operators.

Will we then be able to overload the assignment operator in C#?

-- Rick
 
Rick,
Why would you want to?

With overloading implicit & explicit operators why would you want to
overload the assignment operator?

As for if C# is going to or not going to support overloading the assignment
operator, all I can say is what is in the article I referenced in my earlier
post.

Just a thought
Jay
 
With overloading implicit & explicit operators why would you want to
overload the assignment operator?

You're suggesting that:

MyStruct A = new MyStruct();
<some operations on A>
MyStruct B = new MyStruct(A);

Is better than:

MyStruct A = new MyStruct();
MyStruct B = new MyStruct();
<some operations on A>
B = A;

-- Rick
 
Rick,
No. My question is not suggesting anything, my question is asking a
question. I restated my first question "Why would you want to overload the
assignment operator?", Maybe I inverted the second question, and I should
have asked "What would you do with an overloaded assignment operator that
you cannot do with implicit & explicit operators?"

Again these are questions, not suggestions. If you answer the questions,
then maybe I or someone else can give you a plausible answer.

I am not seeing, as you did not demonstrate, in your example how overloading
the assignment operator will help, Care to explain what you are thinking,
what you are after in your example.

Remember I am not suggesting anything, I am asking you a question on what
you are wanting in an overloaded assignment operator!

Thanks for understanding.

Jay
 
Remember I am not suggesting anything, I am asking you a question on what
you are wanting in an overloaded assignment operator!

So that I can do this:

In a practical application, there would be operations on B, also. You
want a concrete example? Suppose that A and B represent the tuning
registers on two radios and that occasionally I want to synchronize
them.

-- Rick
 
Rick,
want a concrete example? Suppose that A and B represent the tuning
registers on two radios and that occasionally I want to synchronize
them.
It would seem that you want to redefine the meaning of what assignment is to
be mean synchronize.

Where assignment means to replace one object with another, and synchronize
means to update part of one object with parts of another object.

Reading your initial example I took it to be assignment, as that is what you
had, now you are telling me you really meant for it to be synchronize.

How is any one other than you, to know that although you are using the
assignment operator you really intend for the synchronize "operation" to be
performed?

Further, if "=" is now synchronize, how do you propose to assign one
MyStruct variable to a different MyStruct variable?

Lastly using the assignment operator to mean synchronize also goes against
the .NET Design Guidelines for Class Library Developers.

<blockquote>
Use operator overloading in cases where it is immediately obvious what the
result of the operation will be. For example it makes sense to be able to
subtract one Time value from another Time value and get a TimeSpan. However,
it is not appropriate to use the or operator to create the union of two
database queries, or to use shift to write to a stream.
</blockquote>

http://msdn.microsoft.com/library/d...l/cpconOperatorOverloadingUsageGuidelines.asp

Notice the "immediately obvious" in that statement.

Personally if I wanted two objects to be synchronized I would have one
object raise events that the other object listened to updating itself
accordingly. Or the class would have a Synchronize or UpdateWith method.

Hope this helps
Jay
 
Doh!
Where assignment means to replace one object with another, and synchronize
means to update part of one object with parts of another object.
Technically I should have stated, "replace one variable with another
variable".

Jay
 
Does that mean no?

-- Rick

P.S. Do you have any examples of how to parse Word XP files using XML?
Does Office 2003 have better support for such an operation?
[RF]
 
Rick,
I believe we had earlier established that current versions of C# do not
support overloading the assignment operator. That all I know about future
versions of C# or VB.NET is what is documented in the roadmap.

http://msdn.microsoft.com/vstudio/productinfo/roadmap.aspx

That the road map does not confirm nor deny that overloading the assignment
operator will be supported in the next or future versions of either C# or
VB.NET.

Hope this helps
Jay

Guinness Mann said:
Does that mean no?

-- Rick

P.S. Do you have any examples of how to parse Word XP files using XML?
Does Office 2003 have better support for such an operation?
[RF]

Rick,
It would seem that you want to redefine the meaning of what assignment is to
be mean synchronize.

Where assignment means to replace one object with another, and synchronize
means to update part of one object with parts of another object.

Reading your initial example I took it to be assignment, as that is what you
had, now you are telling me you really meant for it to be synchronize.

How is any one other than you, to know that although you are using the
assignment operator you really intend for the synchronize "operation" to be
performed?

Further, if "=" is now synchronize, how do you propose to assign one
MyStruct variable to a different MyStruct variable?

Lastly using the assignment operator to mean synchronize also goes against
the .NET Design Guidelines for Class Library Developers.

<blockquote>
Use operator overloading in cases where it is immediately obvious what the
result of the operation will be. For example it makes sense to be able to
subtract one Time value from another Time value and get a TimeSpan. However,
it is not appropriate to use the or operator to create the union of two
database queries, or to use shift to write to a stream.
</blockquote>

http://msdn.microsoft.com/library/d...l/cpconOperatorOverloadingUsageGuidelines.asp

Notice the "immediately obvious" in that statement.

Personally if I wanted two objects to be synchronized I would have one
object raise events that the other object listened to updating itself
accordingly. Or the class would have a Synchronize or UpdateWith method.


Hope this helps
Jay
 
Back
Top