1

Title is clear: how can I change a value in C# depending on destination architecture? In particular, I want to change a string depending on x86 or x64. Many Thanks!

Edit: I need to check if an x64 Office version is installed if my application is x64 too.

5
  • 2
    No, question and title are not clear. Change a string from what to what? Commented Jul 17, 2013 at 21:14
  • No such a Question, What do you mean?
    – Alyafey
    Commented Jul 17, 2013 at 21:15
  • 2
    Environment.Is64BitProcess might be useful.
    – Matthew
    Commented Jul 17, 2013 at 21:15
  • What do you want to do if you're running on a 32-bit CLR but on an x64 processor?
    – Jon Skeet
    Commented Jul 17, 2013 at 21:20
  • Ok, Thanks! Environment.Is64BitProcess works. I didn't know there were such a simple possibility to "read" that. Thank you again. Commented Jul 17, 2013 at 21:23

3 Answers 3

2

This should get you what you're looking for:

 string platform = IntPtr.Size == 4 ? "x86" : "x64";
0

Environment.Is64BitProcess should do the trick

1
  • The simplest way. I'm a newbie, APIs are still not well known to me. Commented Jul 17, 2013 at 21:30
0

You can use IntPtr.Size

string foobar = String.Empty;

if (IntPtr.Size == 4) //32-bit
    foobar = "foo";
else if (IntPtr.Size == 8) //64-bit
    foobar = "bar";

see also:

How to detect Windows 64-bit platform with .NET?

The answer chosen is pretty darn good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.