Hi all,
I need to sum two classes in this way
MyClass CT = myCollectionOfM yClass[0];
MyClass C1 = myCollectionOfM yClass[1];
CT = CT + C1;
In myClass exists the method to overload + operator and the method
looks like this:
public override operator +(MyClass class1, MyClass class2)
{
MyClass class3 = new MyClass();
class3.property 1 = class1.property 1 + class2.property 2;
.......
return class3;
}
If I execute this code, the value of CT.property1 is 0. Also if
C1.property is 1.
To obtain the correct result (1) I must to change the code in this
way:
public override operator +(MyClass class1, MyClass class2)
{
MyClass class3 = class1;
class3.property 1 = class1.property 1 + class2.property 2;
.......
return class3;
}
It seems that when I create a new istance of MyClass in the overloaded
method, the CT class was cleared.
Anyone knows the correct way to do this????
Bye
Sapo
I need to sum two classes in this way
MyClass CT = myCollectionOfM yClass[0];
MyClass C1 = myCollectionOfM yClass[1];
CT = CT + C1;
In myClass exists the method to overload + operator and the method
looks like this:
public override operator +(MyClass class1, MyClass class2)
{
MyClass class3 = new MyClass();
class3.property 1 = class1.property 1 + class2.property 2;
.......
return class3;
}
If I execute this code, the value of CT.property1 is 0. Also if
C1.property is 1.
To obtain the correct result (1) I must to change the code in this
way:
public override operator +(MyClass class1, MyClass class2)
{
MyClass class3 = class1;
class3.property 1 = class1.property 1 + class2.property 2;
.......
return class3;
}
It seems that when I create a new istance of MyClass in the overloaded
method, the CT class was cleared.
Anyone knows the correct way to do this????
Bye
Sapo
Comment