Sep 03
It’s easy to determine if your C# application is 64-bit. Just check the Size property of IntPtr. If it’s 8, then your application is 64-bit. If it’s 4, then your application is 32-bit.
Here is a simple C# console program to demonstrate this:
using System; namespace CSharp411 { class Program { static void Main( string[] args ) { int bits = IntPtr.Size * 8; Console.WriteLine( "{0}-bit", bits ); Console.ReadLine(); } } }
And there is no way that this might go wrong somehow?
I suppose anything can go wrong with software. 😉
But I tested this with a 32-bit app on x86 and x64, and a 64-bit app on x64.
It should work in all cases (including when we go to 128-bit, if that happens in our lifetime) because the application “bit-ness” determines the size of the pointers.
Good Tip!
Very useful
Hi, I found your blog on this new directory of WordPress Blogs at blackhatbootcamp.com/listofwordpressblogs. I dont know how your blog came up, must have been a typo, i duno. Anyways, I just clicked it and here I am. Your blog looks good. Have a nice day. James.
This is exactly what I was looking for. Thanks bro!
Thanks!
Only problem is if you’re using resources that are 32-bit only and have to force your app to be virtualized on a 64-bit os, but then need to call external resources which could be sensitive to which version of the OS you’re running.
Why not just use
Environment.Is64BitOperatingSystem Property ?
http://msdn.microsoft.com/en-us/library/system.environment.is64bitoperatingsystem.aspx
There is also Environment.Is64BitProcess Property.
Environment.Is64BitOperatingSystem was only added in .Net 4.0