Hi, If you append the character "L", it will work: long imonth = 10 * 1000000000L; I am still looking for the exact reason, but as far as I know, any literal numeric value (like 10000000) which is greater than an "int" is assumed a "long" by the compiler. I'll post if I find something useful, VivekHello Everybody
Line 19: long long2 = 9223372036854775807;
Line 20: long imonth2 = 10 * 10000000000;
Line 21: long imonth = 10 * 1000000000;Why 21 Line Error? Line 19, 20 is no problem. I am using ASP2.0 and IIS6.
Many thanks.
So why not this one?
In my opinion, the reason could be that the C# compiler is assuming a default value for the literal 1000000000 which could me something greater than what a long fits in, and unless we force it to makeit a long (by appending an "L"), an overflow error will occur. Ofcourse this is illogical, as in the case above this line, its working fine (even with an extra digit).
The operation overflows at compile time in checked mode
最新推荐文章于 2026-06-24 10:18:21 发布
本文讨论了在使用C#进行编程时遇到的一个关于长整型变量溢出的问题。作者发现当尝试将两个大的整数相乘并赋值给一个长整型变量时出现了错误,但在数值后面加上'L'后问题得到了解决。文章探讨了可能的原因,并提出了疑问。

231

被折叠的 条评论
为什么被折叠?



