INT = INT * INT [英] int=int*int

查看:112
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆