394 ◾ Appendix D
of the post-increment and the manipulation of the object, the compiler
would then assign this copy to the original operand.
Example D13: Design Confusion: C# Overloaded Operator++
// only one increment definition
// => used for both pre & post increment
// => ??DESIGN??: destructive OR non-destructive??
// version #1: directly modify operand
public static TypeA operator++(TypeA operand) // #D13.1
{ operand.data++; // state change for operand
return operand
}
// version #2: construct copy, modify and return copy
public static TypeA operator+(TypeA operand) // #D13.2
{ TypeA separateCopy = new TypeA();
separateCopy.data = operand.data + 1; //operand untouched
return separateCopy;
}
Which version is correct? e ...