Class = Class (operator overriding)

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

Guest

Why it's not possible to override operator "=" in C#? I have Class - Class1
with one property Prop1. For example

Class1 x = new Class1(); x.Prop1 = "this is x";
Class1 y = new Class1(); y.Prop1 = "this is y";
y = x;

now these (x and y) are two variables looking on one object :[ - changing
one object another object is aleready changing

I need a class which will JUST gather a variables from another class (such
as System.String). I'ts important to use exactly "=" operator, not an
property or IConvertible.Convert()

Thanks a lot, sory about english.
 
If I remember "design decision" as it was most often used incorrectly.

It looks like to me you want to do something like :

y=x.Clone();

You can do this by implementing the IClonable interface (IMO it's cleaner
than doing this by using =)

Patrice
 
Back
Top