Environment.OSVersion Property

Definition

Gets the current platform identifier and version number.

public:
 static property OperatingSystem ^ OSVersion { OperatingSystem ^ get(); };
public static OperatingSystem OSVersion { get; }
member this.OSVersion : OperatingSystem
Public Shared ReadOnly Property OSVersion As OperatingSystem

Property Value

OperatingSystem

The platform identifier and version number.

Exceptions

This property was unable to obtain the system version.

-or-

The obtained platform identifier is not a member of PlatformID

Remarks

In .NET versions prior to .NET 5.0, Environment.OSVersion returns an OS version that may be incorrect when an application runs under Windows compatibility mode. For more information, see GetVersionExA function remarks. In .NET 5.0 and later, Environment.OSVersion always returns the actual OS version. For more information, see Environment.OSVersion returns the correct operating system version.

To identify the operating system platform, for example, Linux or Windows, you can use the RuntimeInformation.IsOSPlatform method.

Applies to