int32,int64的别名

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.

  1. 为什么我得到这个错误,虽然我使用int.
  2. 什么是别名Int32Int64
  3. 当使用Int32Int64,它依赖于操作系统?

Bol*_*ock 5

Int32对应int,Int64对应于long.对于大多数一般用途,您可以使用32位整数; 但是如果你需要非常大的数字则使用long整数(64位).

当您分配Int64.MaxValue给a时int,您隐式地将a long(Int64)转换为int(Int32),这不起作用.此外,该值太大而不适合32位整数.