INT = INT * INT [英] int=int*int
问题描述
嗨
我是csharp的新手
为什么
int x = 999999999;
int y = 1;
y = x * x;
Response.Write(y);
不会引发错误而新值(y)错误?
谢谢
< blockquote>你期待什么答案?
" JohnZing" <乔********** @ S.P.A.M.yahoo.com>在消息中写道
新闻:Xn ********************************** @ 207.46 .2 48.16 ...
嗨
我是csharp的新手
为什么
int x = 999999999;
int y = 1;
y = x * x;
Response.Write(y);
不会引发错误,新值(y)错误?
谢谢
JohnZing< jo ********** @ SPAMyahoo.com>写道:为什么
int x = 999999999;
int y = 1;
y = x * x;
Response.Write (y);
不会引发错误并且新值(y)错误?
不是。默认情况下,算术在C#中是未选中的,因此操作基本上是mod(类型的大小),最大值为+ 1 == minvalue。
''一种非常宽松的描述方式 - 我希望你能明白我的意思。
如果你愿意,你可以检查算术。
有关详细信息,请参阅ECMA规范第14.5.12节。
-
Jon Skeet - < sk *** @ pobox.com> ;
http://www.pobox.com/~skeet
如果回复该组,请不要给我发邮件
因为算术溢出检查在您的项目中关闭
设置(默认)。
或者从命令行构建时,您必须设置/ checked标志。
>
Willy。
" JohnZing" <乔********** @ S.P.A.M.yahoo.com>在消息中写道
新闻:Xn ********************************** @ 207.46 .2 48.16 ...嗨
我是csharp的新手
为什么
int x = 999999999;
int y = 1;
y = x * x;
Response.Write(y);
不会引发错误,新值(y)错误?
谢谢
Hi
i''m new to csharp
why
int x=999999999;
int y=1;
y=x*x;
Response.Write(y);
does not raise an error and the new value (y) is wrong?
thank you
What answer do you expect ?
"JohnZing" <jo**********@S.P.A.M.yahoo.com> wrote in message
news:Xn**********************************@207.46.2 48.16...Hi
i''m new to csharp
why
int x=999999999;
int y=1;
y=x*x;
Response.Write(y);
does not raise an error and the new value (y) is wrong?
thank you
JohnZing <jo**********@S.P.A.M.yahoo.com> wrote:why
int x=999999999;
int y=1;
y=x*x;
Response.Write(y);
does not raise an error and the new value (y) is wrong?
It''s not. By default, arithmetic is unchecked in C#, so operations are
essentially mod (size of type), in a way that maxvalue+1==minvalue.
That''s a very loose way of describing it - I hope you see what I mean.
If you want, you can make the arithmetic checked though.
See section 14.5.12 of the ECMA spec for more information.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Because the "Arithmetic Overflow checking" is turned off in your project
settings (default).
Or when building from the command line you have to set the /checked flag.
Willy.
"JohnZing" <jo**********@S.P.A.M.yahoo.com> wrote in message
news:Xn**********************************@207.46.2 48.16...Hi
i''m new to csharp
why
int x=999999999;
int y=1;
y=x*x;
Response.Write(y);
does not raise an error and the new value (y) is wrong?
thank you
这篇关于INT = INT * INT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!