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 包含作業系統的相關資訊。
如需目前執行時間作業系統的相關資訊,請擷取 OperatingSystem 屬性所傳 Environment.OSVersion 回的物件。 如需和 屬性和 ToString 方法所 VersionVersionString 傳回之 Windows 作業系統版本及其對應版本號碼的清單,請參閱作業系統版本。
根據設計,類別 OperatingSystem 不是描述作業系統的一般用途方法,而且您無法從 OperatingSystem 類別衍生更包容性的類型。 如果您需要類型來包含作業系統的其他資訊,請建立您自己的類型,然後包含類型的 OperatingSystem 欄位,以及您需要的任何其他欄位、屬性或方法。
Operating |
使用指定的平台識別項和版本物件來初始化 OperatingSystem 類別的新執行個體。 |
Platform |
取得識別作業系統平台的 PlatformID 列舉值。 |
Service |
取得這個 OperatingSystem 物件所代表的 Service Pack 版本。 |
Version |
取得識別作業系統的 Version 物件。 |
Version |
取得目前安裝於作業系統上之平台識別項、版本和 Service Pack 的串連字串表示。 |
Clone() |
建立與這個執行個體相同的 OperatingSystem 物件。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
Get |
做為預設雜湊函式。 (繼承來源 Object) |
Get |
已淘汰.
使用將這個執行個體還原序列化所需的資料,填入 SerializationInfo 物件。 |
Get |
取得目前執行個體的 Type。 (繼承來源 Object) |
Is |
指出目前的應用程式是否在 Android 上執行。 |
Is |
檢查 Linux 命令 |
Is |
指出目前的應用程式是否在瀏覽器中以 WASM 形式執行。 |
Is |
指出目前的應用程式是否在 FreeBSD 上執行。 |
Is |
檢查 Linux 命令 |
IsIOS() |
指出目前的應用程式是在 iOS 或 MacCatalyst 上執行。 |
Is |
檢查) 傳回 |
Is |
指出目前的應用程式是否在 Linux 上執行。 |
Is |
指出目前的應用程式是否在 MacCater 上執行。 |
Is |
檢查 Apple 檔中) 與≤版本比較一樣,查看 MacCats 版本 (iOS 版本。 用來保護在指定 Mac Api 版本中新增的 API。 |
Is |
指出目前的應用程式是否在 macOS 上執行。 |
Is |
檢查) 傳 |
Is |
指出目前的應用程式是否正在指定的平台上執行。 |
Is |
檢查作業系統版本是否大於或等於指定的平台版本。 這個方法可以用來保護在指定的 OS 版本中新增的 API。 |
Is |
指出目前的應用程式是否在 tvOS 上執行。 |
Is |
檢查) 傳回 |
Is |
指出目前的應用程式是否以 WASI 的形式執行。 |
Is |
指出目前的應用程式是否在 watchOS 上執行。 |
Is |
檢查) 傳 |
Is |
指出目前的應用程式是否在 Windows 上執行。 |
Is |
檢查) 傳 |
Memberwise |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
To |
將這個 OperatingSystem 物件的值轉換成對等的字串表示。 |
產品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |