Can anyone explain why the below code throws an error. It can easily be fixed by either casting the -1 value to a decimal (-1M), by changing the operator overload to accept an i
It works fine (on my machine) in both VS 2008 and VS 2010. BTW, your implementation of *
is incorrect. It should be:
public static MyObject operator *(MyObject value1, int value2)
{
return new MyObject(value1.myValue * value2);
}
Probably you've meant operator *(MyObject value1, decimal value2)
which is really failing.