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

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.


Pre .NET 4 it was suggested to use the size of an IntPtr (4 for 32 bit and 8 for 64 bit). However, this doesn't give you the bitness of the machine - it gives you the bitness of the CLR that is being used.

That is an important difference if you are running inside a 32 bit process, such as application add-ins. I've got a blog post about finding the machines bitness based on WMI:

http://adamhouldsworth.blogspot.com/2010/03/64bit-registry-from-32bit-application.html

Note however, that I'm still unclear if this will truely represent the current OS bitness (as it's using the processor).

For the vast majority of situations, under normal compilation (AnyCPU) running your own app, IntPtr will suffice.

In .NET 4, as others have said, there is now Environment.Is64BitProcess and Environment.Is64BitOperatingSystem.


In .Net 4.0 you can use

Environment.Is64BitProcess and
Environment.Is64BitOperatingSystem

Tags:

C#

.Net