OperatingSystem 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示有关操作系统的信息,如版本和平台标识符。 此类不能被继承。
public ref class OperatingSystem sealed : ICloneable, System::Runtime::Serialization::ISerializablepublic ref class OperatingSystem sealed : ICloneablepublic sealed class OperatingSystem : ICloneable, System.Runtime.Serialization.ISerializable[System.Serializable]
public sealed class OperatingSystem : ICloneable[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class OperatingSystem : ICloneable, System.Runtime.Serialization.ISerializabletype OperatingSystem = class
    interface ICloneable
    interface ISerializable[<System.Serializable>]
type OperatingSystem = class
    interface ICloneable[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type OperatingSystem = class
    interface ICloneable
    interface ISerializablePublic NotInheritable Class OperatingSystem
Implements ICloneable, ISerializablePublic NotInheritable Class OperatingSystem
Implements ICloneable- 继承
- 
				OperatingSystem
- 属性
- 实现
示例
下面的代码示例使用 OperatingSystem 对象显示有关运行时操作系统的信息。
using System;
public class Example
{
   public static void Main()
   {
      var os = Environment.OSVersion;
      Console.WriteLine("Current OS Information:\n");
      Console.WriteLine("Platform: {0:G}", os.Platform);
      Console.WriteLine("Version String: {0}", os.VersionString);
      Console.WriteLine("Version Information:");
      Console.WriteLine("   Major: {0}", os.Version.Major);
      Console.WriteLine("   Minor: {0}", os.Version.Minor);
      Console.WriteLine("Service Pack: '{0}'", os.ServicePack);
   }
}
// If run on a Windows 8.1 system, the example displays output like the following:
//       Current OS Information:
//
//       Platform: Win32NT
//       Version String: Microsoft Windows NT 6.2.9200.0
//       Version Information:
//          Major: 6
//          Minor: 2
//       Service Pack: ''
// If run on a Windows 7 system, the example displays output like the following:
//       Current OS Information:
//
//       Platform: Win32NT
//       Version String: Microsoft Windows NT 6.1.7601 Service Pack 1
//       Version Information:
//          Major: 6
//          Minor: 1
//       Service Pack: 'Service Pack 1'
open System
let os = Environment.OSVersion
printfn "Current OS Information:\n"
printfn $"Platform: {os.Platform:G}"
printfn $"Version String: {os.VersionString}"
printfn $"Version Information:"
printfn $"   Major: {os.Version.Major}"
printfn $"   Minor: {os.Version.Minor}"
printfn $"Service Pack: '{os.ServicePack}'"
// If run on a Windows 8.1 system, the example displays output like the following:
//       Current OS Information:
//
//       Platform: Win32NT
//       Version String: Microsoft Windows NT 6.2.9200.0
//       Version Information:
//          Major: 6
//          Minor: 2
//       Service Pack: ''
// If run on a Windows 7 system, the example displays output like the following:
//       Current OS Information:
//
//       Platform: Win32NT
//       Version String: Microsoft Windows NT 6.1.7601 Service Pack 1
//       Version Information:
//          Major: 6
//          Minor: 1
//       Service Pack: 'Service Pack 1'
Module Example
   Public Sub Main()
      Dim os As OperatingSystem = Environment.OSVersion
      Console.WriteLine("Current OS Information:")
      Console.WriteLine()
      Console.WriteLine("Platform: {0:G}", os.Platform)
      Console.WriteLine("Version String: {0}", os.VersionString)
      Console.WriteLine("Version Information:")
      Console.WriteLine("   Major: {0}", os.Version.Major)
      Console.WriteLine("   Minor: {0}", os.Version.Minor)
      Console.WriteLine("Service Pack: '{0}'", os.ServicePack)
   End Sub
End Module
' If run on a Windows 8.1 system, the example displays output like the following:
'       Current OS Information:
'
'       Platform: Win32NT
'       Version String: Microsoft Windows NT 6.2.9200.0
'       Version Information:
'          Major: 6
'          Minor: 2
'       Service Pack: ''
' If run on a Windows 7 system, the example displays output like the following:
'       Current OS Information:
'
'       Platform: Win32NT
'       Version String: Microsoft Windows NT 6.1.7601 Service Pack 1
'       Version Information:
'          Major: 6
'          Minor: 1
'       Service Pack: 'Service Pack 1'
注解
OperatingSystem类包含有关操作系统的信息。
有关当前运行时操作系统的信息,请 OperatingSystem 检索 属性 Environment.OSVersion 返回的对象。 有关 Windows 操作系统版本及其由 Version 和 VersionString 属性和 ToString 方法返回的相应版本号的列表,请参阅 操作系统版本。
根据设计, OperatingSystem 类不是描述操作系统的常规用途方法,并且不能从 OperatingSystem 类派生更具包容性的类型。 如果需要类型以包含有关操作系统的其他信息,请创建自己的类型,然后包括 类型的 OperatingSystem 字段以及所需的任何其他字段、属性或方法。
构造函数
| OperatingSystem(PlatformID, Version) | 使用指定的平台标识符值和版本对象来初始化 OperatingSystem 类的新实例。 | 
属性
| Platform | 获取标识操作系统平台的 PlatformID 枚举值。 | 
| ServicePack | 获取此 OperatingSystem 对象表示的 Service Pack 版本。 | 
| Version | 获取标识操作系统的 Version 对象。 | 
| VersionString | 获取平台标识符、版本和当前安装在操作系统上的 Service Pack 的连接字符串表示形式。 | 
方法
| Clone() | 创建与此实例相同的 OperatingSystem 对象。 | 
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetObjectData(SerializationInfo, StreamingContext) | 
				已过时.
			 使用反序列化此实例所需的数据填充 SerializationInfo 对象。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| IsAndroid() | 指示当前应用程序是否在 Android 上运行。 | 
| IsAndroidVersionAtLeast(Int32, Int32, Int32, Int32) | 检查 Linux 命令  | 
| IsBrowser() | 指示当前应用程序是否在浏览器中作为 WASM 运行。 | 
| IsFreeBSD() | 指示当前应用程序是否正在 FreeBSD 上运行。 | 
| IsFreeBSDVersionAtLeast(Int32, Int32, Int32, Int32) | 检查 Linux 命令  | 
| IsIOS() | 指示当前应用程序是在 iOS 还是 MacCatalyst 上运行。 | 
| IsIOSVersionAtLeast(Int32, Int32, Int32) | 检查) 返回  | 
| IsLinux() | 指示当前应用程序是否在 Linux 上运行。 | 
| IsMacCatalyst() | 指示当前应用程序是否在 Mac Catalyst 上运行。 | 
| IsMacCatalystVersionAtLeast(Int32, Int32, Int32) | 使用≤版本比较检查 Apple 文档) 中显示的 Mac Catalyst 版本 (iOS 版本。 用于保护在给定的 Mac Catalyst 版本中添加的 API。 | 
| IsMacOS() | 指示当前应用程序是否正在 macOS 上运行。 | 
| IsMacOSVersionAtLeast(Int32, Int32, Int32) | 检查) 返回  | 
| IsOSPlatform(String) | 指示当前应用程序是否正在指定平台上运行。 | 
| IsOSPlatformVersionAtLeast(String, Int32, Int32, Int32, Int32) | 检查操作系统版本是否大于或等于指定的平台版本。 此方法可用于保护在指定 OS 版本中添加的 API。 | 
| IsTvOS() | 指示当前应用程序是否正在 tvOS 上运行。 | 
| IsTvOSVersionAtLeast(Int32, Int32, Int32) | 检查) 返回  | 
| IsWasi() | 指示当前应用程序是否作为 WASI 运行。 | 
| IsWatchOS() | 指示当前应用程序是否正在 watchOS 上运行。 | 
| IsWatchOSVersionAtLeast(Int32, Int32, Int32) | 检查) 返回  | 
| IsWindows() | 指示当前应用程序是否正在 Windows 上运行。 | 
| IsWindowsVersionAtLeast(Int32, Int32, Int32, Int32) | 检查) 返回  | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 将此 OperatingSystem 对象的值转换为其等效的字符串表示形式。 |