Assignment operator can NOT be overloaded !

  • Thread starter Thread starter Christian
  • Start date Start date
C

Christian

Hi,

operator=() does not exist in C# ?

How then can I implement a custom assignment between 2 objects of type say
MyClass ?

Thnx
Chris
 
Christian,

You can't. The reason for this is that the designers wanted the rules
for assignment to be consistent throughout. You will have to create a
method which is called which will do what you want (and I think is more
readable as well).

Hope this helps.
 
Christian said:
operator=() does not exist in C# ?

No, thank goodness.
How then can I implement a custom assignment between 2 objects of type say
MyClass ?

You can give implicit conversion operators if you must - but personally
I'd avoid them, and either make the conversion operator explicit or (as
Nicholas suggested) use a method instead.
 
Back
Top