SEHException .NET难题 [英] SEHException .net Conundrum
问题描述
任何人都可以解释为什么低于code抛出一个错误。它可以很容易地固定或者-1值转换为一十进制(-1M),通过改变运算符重载接受一个int或不使用一个可为空的对象。
我注意到犯规在VS2010 VS2008只是抛出的错误。
类节目
{
静态无效的主要(字串[] args)
{
VAR 01 =新的MyObject(新MyObject来(2.34M))?;
O1 * = -1;
}
}
公共结构为MyObject
{
公众为MyObject(十进制myvalue的)
{
this.myValue = myvalue的;
}
私人十进制myvalue的;
公共静态为MyObject符*(myObject的值1,十进制值2)
{
value1.myValue * =值;
返回值1;
}
}
没有摄制与给定的code段。您所使用的code但是非常类似于落在了一个旧的错误,在C#编译器的那种code。细节是在<一个href="http://stackoverflow.com/questions/5188671/c-implicit-conversion-to-system-double-with-a-nullable-struct-via-compiler-gener">this螺纹,埃里克利珀已经意识到这一点。
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;
}
}
No repro with the given code snippet. The code you used however strongly resembles the kind of code that falls over on an old bug in the C# compiler. The details are in this thread, Eric Lippert is already aware of it.
这篇关于SEHException .NET难题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!