Using C#, how to get whether my machine is 64bit or 32bit?

后端 未结 6 1077
陌清茗
陌清茗 2021-02-19 14:23

Using C#, I would like to create a method that retunrs whether my machine is 64 or 32-bit.

Is there anybody who knows how to do that?

6条回答
  •  佛祖请我去吃肉
    2021-02-19 15:17

    You can check using IntPtr size. IntPtr size is 4 for 32 bit OS and 8 for 64 bit OS

    /// Is64s the bit operating system.
    /// 
    if (IntPtr.Size == 8)
        // 64Bit
    else
        // 32bit
    

    Type: System.Int32

    The size of a pointer or handle in this process, measured in bytes. The value of this property is 4 in a 32-bit process, and 8 in a 64-bit process. You can define the process type by setting the /platform switch when you compile your code with the C# and Visual Basic compilers.

提交回复
热议问题