get system architecture in csharp

To get the system architecture in C#, you can use the System.Runtime.InteropServices.RuntimeInformation class which provides information about the runtime and platform that the application is running on.

main.cs
using System.Runtime.InteropServices;

...

string architecture = RuntimeInformation.ProcessArchitecture.ToString();
117 chars
6 lines

The RuntimeInformation.ProcessArchitecture property returns a System.Runtime.InteropServices.Architecture enum value that represents the architecture of the currently executing process. You can then use the ToString() method to convert it to a string representation. This value will be one of X86, X64, or Arm.

Note: This code requires .NET Core 2.0 or later, or .NET Framework 4.7 or later.

gistlibby LogSnag