OperatingSystem 類別

定義

表示作業系統的資訊,例如版本和平台識別項。 此類別無法獲得繼承。

public ref class OperatingSystem sealed : ICloneable, System::Runtime::Serialization::ISerializable
public ref class OperatingSystem sealed : ICloneable
public 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.ISerializable
type 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 ISerializable
Public NotInheritable Class OperatingSystem
Implements ICloneable, ISerializable
Public 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 回的物件。 如需和 屬性和 ToString 方法所 VersionVersionString 傳回之 Windows 作業系統版本及其對應版本號碼的清單,請參閱作業系統版本

根據設計,類別 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 命令 uname 傳回的 Android 版本 () 是否大於或等於指定的版本。 這個方法可以用來保護在指定版本中新增的 API。

IsBrowser()

指出目前的應用程式是否在瀏覽器中以 WASM 形式執行。

IsFreeBSD()

指出目前的應用程式是否在 FreeBSD 上執行。

IsFreeBSDVersionAtLeast(Int32, Int32, Int32, Int32)

檢查 Linux 命令 uname 傳回的 FreeBSD 版本 () 是否大於或等於指定的版本。 這個方法可以用來保護在指定版本中新增的 API。

IsIOS()

指出目前的應用程式是在 iOS 或 MacCatalyst 上執行。

IsIOSVersionAtLeast(Int32, Int32, Int32)

檢查) 傳回 libobjc.get_operatingSystemVersion (的 iOS/MacCatalyst 版本是否大於或等於指定的版本。 這個方法可以用來保護在指定的 iOS 版本中新增的 API。

IsLinux()

指出目前的應用程式是否在 Linux 上執行。

IsMacCatalyst()

指出目前的應用程式是否在 MacCater 上執行。

IsMacCatalystVersionAtLeast(Int32, Int32, Int32)

檢查 Apple 檔中) 與≤版本比較一樣,查看 MacCats 版本 (iOS 版本。 用來保護在指定 Mac Api 版本中新增的 API。

IsMacOS()

指出目前的應用程式是否在 macOS 上執行。

IsMacOSVersionAtLeast(Int32, Int32, Int32)

檢查) 傳 libobjc.get_operatingSystemVersion 回 (的 macOS 版本是否大於或等於指定的版本。 這個方法可以用來保護在指定的 macOS 版本中新增的 API。

IsOSPlatform(String)

指出目前的應用程式是否正在指定的平台上執行。

IsOSPlatformVersionAtLeast(String, Int32, Int32, Int32, Int32)

檢查作業系統版本是否大於或等於指定的平台版本。 這個方法可以用來保護在指定的 OS 版本中新增的 API。

IsTvOS()

指出目前的應用程式是否在 tvOS 上執行。

IsTvOSVersionAtLeast(Int32, Int32, Int32)

檢查) 傳回 libobjc.get_operatingSystemVersion (的 tvOS 版本是否大於或等於指定的版本。 這個方法可以用來保護在指定的 tvOS 版本中新增的 API。

IsWasi()

指出目前的應用程式是否以 WASI 的形式執行。

IsWatchOS()

指出目前的應用程式是否在 watchOS 上執行。

IsWatchOSVersionAtLeast(Int32, Int32, Int32)

檢查) 傳 libobjc.get_operatingSystemVersion 回 (的 watchOS 版本是否大於或等於指定的版本。 這個方法可以用來保護在指定的 watchOS 版本中新增的 API。

IsWindows()

指出目前的應用程式是否在 Windows 上執行。

IsWindowsVersionAtLeast(Int32, Int32, Int32, Int32)

檢查) 傳 RtlGetVersion 回 (的 Windows 版本是否大於或等於指定的版本。 這個方法可以用來保護在指定的 Windows 版本中新增的 API。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

將這個 OperatingSystem 物件的值轉換成對等的字串表示。

適用於