Is there some sort of C# directive to use when using a development machine (32-bit or 64-bit) that says something to the effect of:
if (32-bit Vista) // set a property to true else if (64-bit Vista) // set a property to false
but I want to do this in Visual Studio as I have an application I'm working on that needs to be tested in 32/64 bit versions of Vista.
Is something like this possible?
Can you do it at runtime?
if (IntPtr.Size == 4)
// 32 bit
else if (IntPtr.Size == 8)
// 64 bit
There are two conditions to be aware of with 64-bit. First is the OS 64-bit, and second is the application running in 64-bit. If you're only concerned about the application itself you can use the following:
if( IntPtr.Size == 8 )
// Do 64-bit stuff
else
// Do 32-bit
At runtime, the JIT compiler can optimize away the false conditional because the IntPtr.Size property is constant.
Incidentally, to check if the OS is 64-bit we use the following
if( Environment.GetEnvironmentVariable( "PROCESSOR_ARCHITEW6432" ) != null )
// OS is 64-bit;
else
// OS is 32-bit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With