Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

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?

like image 578
Billy ONeal Avatar asked Jul 23 '10 13:07

Billy ONeal


1 Answers

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.

like image 158
Richard Avatar answered Oct 25 '22 12:10

Richard