C#判斷當前運行環境是否64bit

C#的應用程序,不強制指定目標平臺爲x86或x64,那麼運行時想判斷當前環境究竟是不是64bit,能夠利用 IntPtr.Size 屬性:ide

  
  
           
  
  
  1. /// <summary> 
  2. /// 斷定是否運行於64bit下 
  3. /// </summary> 
  4. /// <returns>是否爲64bit</returns> 
  5. public static bool Is64bit() 
  6.     return IntPtr.Size == 8; 

 

關於IntPtr.Size,MSDN中的介紹以下:spa

  
  
           
  
  
  1. public static int Size { get; } 
  2.  
  3. 屬性值 
  4. 類型:System.Int32 
  5.  
  6. 此平臺上的指針或句柄的大小,按字節計。此屬性的值在 32 位平臺上爲 4,在 64 位平臺上爲 8。 
相關文章
相關標籤/搜索