閱讀英文

共用方式為


PlatformID 列舉

定義

識別組件所支援的作業系統或平台。

C#
public enum PlatformID
C#
[System.Serializable]
public enum PlatformID
C#
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum PlatformID
繼承
PlatformID
屬性

欄位

MacOSX 6

作業系統是 Macintosh。 這個值是由 Silverlight 傳回。 在 .NET Core 上,替代的值為 Unix

Other 7

其他作業系統。 這包括瀏覽器 (WASM)。

Unix 4

作業系統是 Unix。

Win32NT 2

作業系統是 Windows NT 或更新版本。

Win32S 0

作業系統是 Win32。 這個值不再使用。

Win32Windows 1

作業系統是 Windows 95 或 Windows 98。 這個值不再使用。

WinCE 3

作業系統是 Windows CE。 這個值不再使用。

Xbox 5

開發平台為 Xbox 360。 這個值不再使用。

範例

下列範例示範如何使用 PlatformID 類別來識別目前正在執行的作業系統:

C#
// This example demonstrates the PlatformID enumeration.
using System;

class Sample
{
    public static void Main()
    {
    string msg1 = "This is a Windows operating system.";
    string msg2 = "This is a Unix operating system.";
    string msg3 = "ERROR: This platform identifier is invalid.";

// Assume this example is run on a Windows operating system.

    OperatingSystem os = Environment.OSVersion;
    PlatformID     pid = os.Platform;
    switch (pid)
        {
        case PlatformID.Win32NT:
        case PlatformID.Win32S:
        case PlatformID.Win32Windows:
        case PlatformID.WinCE:
            Console.WriteLine(msg1);
            break;
        case PlatformID.Unix:
            Console.WriteLine(msg2);
            break;
        default:
            Console.WriteLine(msg3);
            break;
        }
    }
}
/*
This example produces the following results:

This is a Windows operating system.
*/

備註

Environment.OSVersion使用 和 OperatingSystem.Platform 屬性來取得 PlatformID 目前執行之作業系統或開發平臺的列舉。 PlatformID使用 列舉來協助判斷目前的作業系統或開發平臺是否支援您的應用程式。

您可以使用每個 PlatformID 列舉成員的基礎整數值作為 PlatformId SignTool.exe (符號工具) 公用程式的引數。

適用於

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.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
.NET Standard 2.0, 2.1