S
Sapo19875
Hi all,
I need to sum two classes in this way
MyClass CT = myCollectionOfMyClass[0];
MyClass C1 = myCollectionOfMyClass[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.property1 = class1.property1 + class2.property2;
.......
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.property1 = class1.property1 + class2.property2;
.......
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 = myCollectionOfMyClass[0];
MyClass C1 = myCollectionOfMyClass[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.property1 = class1.property1 + class2.property2;
.......
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.property1 = class1.property1 + class2.property2;
.......
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