0 c#
class Program
{
static void Main(string[] args)
{
Int64 a = Int64.MaxValue;
Int64 b= Int64.MinValue;
try
{
checked
{
Int64 m = a * b;
}
}
catch (OverflowException ex)
{
Console.WriteLine("over flow exception");
Console.Read();
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果变量声明为int,我得到编译错误,转换是从int到long的requreid.
Int32和Int64Int32和Int64,它依赖于操作系统?Int32对应int,Int64对应于long.对于大多数一般用途,您可以使用32位整数; 但是如果你需要非常大的数字则使用long整数(64位).
当您分配Int64.MaxValue给a时int,您隐式地将a long(Int64)转换为int(Int32),这不起作用.此外,该值太大而不适合32位整数.
| 归档时间: |
|
| 查看次数: |
2526 次 |
| 最近记录: |