Open In App

C# Program to Check if Operating System is 64-bit OS or Not Using Environment Class

Last Updated : 01 Nov, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that retrieves command-line arguments information, exit codes information, environment variable settings information, contents of the call stack information, and time since last system boot in milliseconds information. In this article, we will discuss how to check whether running operating systems is 64 bit OS or not using Environment class. So we need to use the Is64BitOperatingSystem property of the Environment class. This property is used to check whether the running operating system is based on 64-Bit architecture or not and returns true if it is 64-bit OS otherwise it will return false.

Syntax:

Environment.Is64BitOperatingSystem

Return Type: The return type of this property is Boolean. It returns true if the OS is 64-bit OS. Otherwise, it will return false.

Example:

C#




// C# program to check whether the given
// OS is 64-bit Os or not. Using the
// Environment class
using System;
  
class GFG{
  
static public void Main()
{
      
    // Declaring a variable of bool type
    // to store the result
    bool outresult;
      
    // Now we determine the current operating system 
    // is 64-bit OS or not. Using the Is64BitOperatingSystem
    // property of Environment class
    outresult = Environment.Is64BitOperatingSystem;
      
    // Display the result
    if (outresult == true)
        Console.WriteLine("Yes! the current operating " +
                          "system is 64-bit OS");
    else
        Console.WriteLine("No! the current operating "
                          "system is not 64-bit OS");
}
}


Output:

Operating System is based 64-bit architecture

When we run the same code in the 32-bit system then the output will be:

Operating System is not based 64-bit architecture

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads