C#的應用程序,不強制指定目標平臺爲x86或x64,那麼運行時想判斷當前環境究竟是不是64bit,能夠利用 IntPtr.Size 屬性:ide
- /// <summary>
- /// 斷定是否運行於64bit下
- /// </summary>
- /// <returns>是否爲64bit</returns>
- public static bool Is64bit()
- {
- return IntPtr.Size == 8;
- }
關於IntPtr.Size,MSDN中的介紹以下:spa
- public static int Size { get; }
- 屬性值
- 類型:System.Int32
- 此平臺上的指針或句柄的大小,按字節計。此屬性的值在 32 位平臺上爲 4,在 64 位平臺上爲 8。