异常的应用程序终止 [英] abnormal Application termination
问题描述
亲爱的所有人,
这是我的应用程序对应的一个大问题.我的应用程序异常终止,显示异常"Int32的超出范围的值".
但是我已经通过演示代码通过单击winform的按钮进行了测试:
Dear all,
It is a big problem corresponds my application. My application is abnormally terminated showing an exception "Out of range value of Int32".
But I have tested by the demo code with a button click on a winform:
int j;
j = Int32.MaxValue;
Random rnd = new Random(10000);
j = j * rnd.Next();
MessageBox.Show("Converted "+j);
但是应用程序并没有终止.
什么可能是叛国罪???:confused:
请帮帮我.
But the application didn''t terminate.
What might be th rreason???:confused:
Please help me.
推荐答案
不起作用的原因是您已经分配了Int32可以容纳的最高值:
the reason it isn''t working is that you already assign the highest value an Int32 can hold:
j = Int32.MaxValue;
然后尝试将其值设置为其自身乘以您随机生成的数字-结果太大,无法存储Int32.
我的猜测是您需要一个long而不是一个int.看看这篇文章,看看是否有帮助:
[ http://www.blackwasp.co.uk/CSharpNumericDataTypes.aspx ]
and then you try to set it''s value as itself multiplied by your randomly generated number - the result is too big for an Int32 to store.
my guess is you need a long instead of an int. have a look at this article and see if it helps:
[http://www.blackwasp.co.uk/CSharpNumericDataTypes.aspx]
示例:
long j;
j = Int32.MaxValue;
Random rnd = new Random(10000);
j = j * rnd.Next();
MessageBox.Show("Converted " + j);
因为如果您将Int32的值乘以2,则可能是Int64的值,这很长;)
如果有帮助,请投票并接受答案.
because if you multiple 2 Int32 value then it may be Int64 value, which is long ;)
Please vote and Accept Answer if it Helped.
我不认为您收到的错误来自Int32
溢出.实际上,您发布的"超出Int32的范围值"的消息甚至似乎都不是.NET异常消息.也许您正在尝试将此值插入数据库?也许是数据库抛出此消息异常.
I don''t think the error you are getting is from the Int32
overflow. In fact the message you posted "Out of range value of Int32" does not even seem to be a .NET exception message. Perhaps you are trying to insert this value into a database? And maybe it''s the DB that''s throwing an exception with this message.
这篇关于异常的应用程序终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!