Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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

  • Last Updated : 24 Oct, 2021

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
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!