OperatingSystem 类

定义

表示有关操作系统的信息,如版本和平台标识符。Represents information about an operating system, such as the version and platform identifier. 此类不能被继承。This class cannot be inherited.

public ref class OperatingSystem sealed : ICloneable, System::Runtime::Serialization::ISerializable
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public sealed class OperatingSystem : ICloneable, System.Runtime.Serialization.ISerializable
type OperatingSystem = class
    interface ICloneable
    interface ISerializable
Public NotInheritable Class OperatingSystem
Implements ICloneable, ISerializable
继承
OperatingSystem
属性
实现

示例

下面的代码示例使用OperatingSystem对象显示有关运行时操作系统的信息。The following code example uses the OperatingSystem object to display information about the runtime operating system.

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'
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类包含有关操作系统的信息。The OperatingSystem class contains information about an operating system.

有关当前运行时操作系统的信息, 请检索OperatingSystem Environment.OSVersion由属性返回的对象。For information about the current runtime operating system, retrieve the OperatingSystem object returned by the Environment.OSVersion property. 有关VersionVersionString属性和ToString方法返回的 windows 操作系统版本及其相应版本号的列表, 请参阅 Windows 开发人员中心上的操作系统版本For a list of Windows operating system versions and their corresponding version numbers returned by the Version and VersionString properties and the ToString method, see Operating System Version on the Windows Dev Center.

按照设计, OperatingSystem类并不是描述操作系统的常规用途, 不能OperatingSystem从类中派生更多的非独占类型。By design, the OperatingSystem class is not a general purpose means of describing an operating system, and you cannot derive a more inclusive type from the OperatingSystem class. 如果需要一个类型来包含有关操作系统的其他信息, 请创建自己的类型, 然后包括类型OperatingSystem的字段以及所需的任何其他字段、属性或方法。If you need a type to contain other information about an operating system, create your own type, then include a field of type OperatingSystem and any additional fields, properties, or methods that you require.

构造函数

OperatingSystem(PlatformID, Version)

使用指定的平台标识符值和版本对象来初始化 OperatingSystem 类的新实例。Initializes a new instance of the OperatingSystem class, using the specified platform identifier value and version object.

属性

Platform

获取标识操作系统平台的 PlatformID 枚举值。Gets a PlatformID enumeration value that identifies the operating system platform.

ServicePack

获取此 OperatingSystem 对象表示的 Service Pack 版本。Gets the service pack version represented by this OperatingSystem object.

Version

获取标识操作系统的 Version 对象。Gets a Version object that identifies the operating system.

VersionString

获取平台标识符、版本和当前安装在操作系统上的 Service Pack 的连接字符串表示形式。Gets the concatenated string representation of the platform identifier, version, and service pack that are currently installed on the operating system.

方法

Clone()

创建与此实例相同的 OperatingSystem 对象。Creates an OperatingSystem object that is identical to this instance.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetObjectData(SerializationInfo, StreamingContext)

使用反序列化此实例所需的数据填充 SerializationInfo 对象。Populates a SerializationInfo object with the data necessary to deserialize this instance.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

将此 OperatingSystem 对象的值转换为其等效的字符串表示形式。Converts the value of this OperatingSystem object to its equivalent string representation.

适用于