It appears in C# you can not override the post decrement operator?
I was "reflectoring" and ran across some code that reflector translated to decimal.op_Decrement(x)
and I was trying to figure out whether it meant --x
or x--
.
public struct IntWrapper
{
public static IntWrapper operator --(IntWrapper value)
{
return new IntWrapper(value.value - 1);
}
public static IntWrapper operator (IntWrapper value)--
{
???
}
private int value;
public IntWrapper(int value)
{
this.value = value;
}
}
Does the framework just use the "pre-decrement" version for the "post-decrement" operation?
Function(oldValueOf_y)
is called AFTER the variable known asy
is decremented. What is passed toFunction()
is a copy ofy
before it was decremented. Thus it would seem that in C#, just as in C++, the semantics of postfix increment/decrement prevent obvious optimizations that the compiler may be able to make with prefix increment/decrement. – Espionage