Search code examples
c#.net

How can I determine the "bit-ness" under which my C# application runs?


A .NET dll can be run as both 32 bit and 64 bit on a machine with an x64 processor. I need to determine at runtime what bitness my application is running under.

Currently I've been doing something like System.IntPtr.Size == 8, but that seems like an ugly hack. Is there a more "correct" way of determining this?


Solution

  • In .NET 4 and beyond, including .NET Core, the System.Environment class has two static properties: Is64BitOperatingSystem and Is64BitProcess. In earlier .NET versions you need to use the IntPtr size approach.