OperatingSystem 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表作業系統的資訊,例如版本與平台識別碼。 無法繼承這個類別。
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 類別包含有關作業系統的資訊。
如需了解目前執行時作業系統的資訊,請檢索由屬性Environment.OSVersion回傳的OperatingSystem物件。 關於 Windows 作業系統版本及其由 and VersionString 屬性和ToString方法回傳Version的對應版本號,請參見作業系統版本。
根據設計,這個 OperatingSystem 類別並非描述作業系統的通用工具,你也無法從這個 OperatingSystem 類別推導出更包容的型別。 如果你需要一個型別來包含作業系統的其他資訊,請建立自己的型別,然後加入一個型態 OperatingSystem 的欄位,以及你需要的其他欄位、屬性或方法。
建構函式
| 名稱 | Description |
|---|---|
| OperatingSystem(PlatformID, Version) |
初始化類別的新實例 OperatingSystem ,使用指定的平台識別碼值與版本物件。 |
屬性
| 名稱 | Description |
|---|---|
| Platform |
會獲得 PlatformID 一個列舉值,以識別作業系統平台。 |
| ServicePack |
會得到這個物件所 OperatingSystem 代表的服務包版本。 |
| Version |
取得 Version 一個用來識別作業系統的物件。 |
| VersionString |
取得目前安裝於作業系統上的平台識別碼、版本與服務包的串接字串表示。 |
方法
| 名稱 | Description |
|---|---|
| Clone() |
建立 OperatingSystem 一個與此實例相同的物件。 |
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
已淘汰.
將該實例反序列化所需的資料填充物件 SerializationInfo 。 |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IsAndroid() |
顯示目前應用程式是否在 Android 上運行。 |
| IsAndroidVersionAtLeast(Int32, Int32, Int32, Int32) |
檢查 Android 版本(由 Linux 指令 |
| IsBrowser() |
顯示目前應用程式是否以 WASM 格式在瀏覽器中執行。 |
| IsFreeBSD() |
顯示目前應用程式是否在 FreeBSD 上執行。 |
| IsFreeBSDVersionAtLeast(Int32, Int32, Int32, Int32) |
檢查 FreeBSD 版本(由 Linux 指令 |
| IsIOS() |
顯示目前應用程式是在 iOS 還是 MacCatalyst 上執行。 |
| IsIOSVersionAtLeast(Int32, Int32, Int32) |
檢查 iOS/MacCatalyst 版本(由 |
| IsLinux() |
顯示目前應用程式是否在 Linux 上執行。 |
| IsMacCatalyst() |
顯示目前應用程式是否在 Mac Catalyst 上執行。 |
| IsMacCatalystVersionAtLeast(Int32, Int32, Int32) |
請查看 Mac Catalyst 版本(如蘋果文件中提供的 iOS 版本),並附有≤版本比較。 用來保護在特定 Mac Catalyst 版本中新增的 API。 |
| IsMacOS() |
顯示目前應用程式是否在 macOS 上運行。 |
| IsMacOSVersionAtLeast(Int32, Int32, Int32) |
檢查 macOS 版本(由 |
| IsOSPlatform(String) |
顯示目前應用程式是否在指定平台上執行。 |
| IsOSPlatformVersionAtLeast(String, Int32, Int32, Int32, Int32) |
檢查作業系統版本是否大於或等於指定平台版本。 此方法可用來保護在指定作業系統版本中新增的 API。 |
| IsTvOS() |
顯示目前應用程式是否在 tvOS 上執行。 |
| IsTvOSVersionAtLeast(Int32, Int32, Int32) |
檢查 tvOS 版本(由 |
| IsWasi() |
顯示目前應用程式是否以 WASI 格式執行。 |
| IsWatchOS() |
顯示目前應用程式是否在 watchOS 上執行。 |
| IsWatchOSVersionAtLeast(Int32, Int32, Int32) |
檢查 watchOS 版本(由 |
| IsWindows() |
顯示目前應用程式是否在 Windows 上運行。 |
| IsWindowsVersionAtLeast(Int32, Int32, Int32, Int32) |
檢查 Windows 版本(由 |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
將此 OperatingSystem 物件的值轉換為其等價的字串表示。 |