You cannot override/overload or otherwise modify
the assignment (=) or new operators in .NET.
There is specific logic that .NET uses for assignment
that is required for the memory management and
garbage collection.
I think what you may want is to override the
implicit and explicit cast operator.
For example:
MyFancyNumberClass mfnc = new MyFancyNumberClass():
// implicit cast
int foo = mfnc;
If you wrote MyFancyNumberClass and you wanted
people to copy it to an int, you'd use the
implicit cast operator to convert mfnc to an
integer.
You can also override explicit casts:
int foo = (int) mfnc;
-c
"apex" <ap*****@sjtu.edu.cn> wrote in message
news:O%****************@TK2MSFTNGP10.phx.gbl...
For example:
MyClass A = new MyClass();
MyClass B = new MyClass();
A.Item1 = ...;
A.Item2 = ...;
B = A;
"Treefrog" <tr******@mountainbikes.co.uk> wrote in message
news:3f********@news.1anetworks.net... "Ashish" <ab*@hotmail.com> wrote in message
news:eR**************@tk2msftngp13.phx.gbl... Code in C++ :-) or just override equals in C#
Ashish
Wouldn't that override "==", not "="?
Can I ask why you would possibly want to override "="? There must be
another solution.
Nathan