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
What I use in my C# code is IntPtr.Size, it equals 4 on 32bit and 8 on 64bit:
string framework = (IntPtr.Size == 8) ? "Framework64" : "Framework";
You can use Predefined Macros to set the properties on compilation
#if (_WIN64)
const bool IS_64 = true;
#else
const bool IS_64 = false;
#endif
You can use a #if
directive and set the value as a compiler switch (or in the project settings):
#if VISTA64
...
#else
...
#endif
and compile with:
csc /d:VISTA64 file1.cs
when compiling a 64 bit build.
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
There is nothing built in that will do this for you. You could always #define your own symbol and use that for conditional compilation if you wish.
Can you do it at runtime?
if (IntPtr.Size == 4)
// 32 bit
else if (IntPtr.Size == 8)
// 64 bit