Do you only need to know which code is running by the caller: 32- or 64-bit? It this is just this, it's way too simple:
static int HowManyBits {
get {
System.IntPtr ptr = System.IntPtr.Zero;
return System.Runtime.InteropServices.Marshal.SizeOf(ptr) * 8;
}
}
For example,
static void Main(string[] args) {
System.Console.WriteLine( string.Format("{0}-bit", HowManyBit) );
}
will output "32-bit" or "64-bit".
Please also see my comment to the Answer by Abhinav.
—SA