Open In App

C# Program to Get the Operating System Version of Computer using Environment Class

Improve
Improve
Like Article
Like
Save
Share
Report

In C#, 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 it retrieves command-line arguments information, exit codes information, environment variable settings information, contents of the call stack information, and time since the last system boot in milliseconds information. In this article, we are going to discuss how to get the operating system version of the computer. So we use the OSVersion property of the Environment class. This property returns the current OS version of the system or platform identifier. It will also return an InvalidOperationException if this property does not get the current version of the system or a platform identifier that is not part of PlatformID. 

Syntax:

Environment.OSVersion

spa

Return: It returns the platform identifier or the version of the system.

Example: 

In the below example, using the OsVersion property of Environment class we find the current OS version of our computer system.

C#




// C# program to get the current operating
// system version of the computer 
// Using Environment Class
using System;
using System.Collections;
  
class GFG
{
  
    static public void Main()
    {
  
        // Display the current OS version of the system 
        // Using OSVersion property of the Environment class
        Console.WriteLine("The current operating System version is " +
                          Environment.OSVersion);
    }
}


Output:

The current operating System version is Unix 20.3.0.0

Last Updated : 24 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads