C# - Environment.OSVersion Property with Example

In this tutorial, we will learn about the C# Environment.OSVersion property with its definition, usage, syntax, and example. By Nidhi Last updated : March 30, 2023

Environment.OSVersion Property

The Environment.OSVersion property is used to the get the operating system version of computer system.


OperatingSystem Environment.OSVersion


  • None

Return Value

This property returns an object of OperatingSytem class, here we converted version values into a string using the ToString() method.


  • System.InvalidOperationException

C# Example of Environment.OSVersion Property

The source code to get the Operating System version of computer using Environment class is given below. The given program is compiled and executed successfully.

using System;
using System.Collections;

class Sample
    //Entry point of Program
    static public void Main()
        string OsVer = "";
        OsVer = Environment.OSVersion.ToString();

        Console.WriteLine("OS Version:\n"+OsVer);


OS Version:
Microsoft Windows NT 6.1.7600.0
Press any key to continue . . .

C# Environment Class Programs »

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.