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 int or by not using a nullable object.
I have noticed the error doesnt get thrown in VS2010 only VS2008.
class Program
{
static void Main(string[] args)
{
var o1 = new MyObject?(new MyObject(2.34M));
o1 *= -1;
}
}
public struct MyObject
{
public MyObject(Decimal myValue)
{
this.myValue = myValue;
}
private Decimal myValue;
public static MyObject operator *(MyObject value1, decimal value2)
{
value1.myValue *= value2;
return value1;
}
}