SEHException .net Conundrum

前端 未结 3 1332
囚心锁ツ
囚心锁ツ 2021-01-25 11:44

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

3条回答
  •  失恋的感觉
    2021-01-25 12:23

    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.

提交回复
热议问题