PlatformID 列舉

定義

識別元件支援的作業系統或平臺。

public enum class PlatformID
[System.Serializable]
public enum PlatformID
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum PlatformID
public enum PlatformID
[<System.Serializable>]
type PlatformID = 
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type PlatformID = 
type PlatformID = 
Public Enum PlatformID
繼承
PlatformID
屬性

欄位

名稱 Description
Win32S 0

作業系統是 Win32s。 這個數值現在已經不再使用。

Win32Windows 1

作業系統為 Windows 95 或 Windows 98。 這個數值現在已經不再使用。

Win32NT 2

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

WinCE 3

作業系統為 Windows CE。 這個數值現在已經不再使用。

Unix 4

作業系統為 Unix。

Xbox 5

開發平台是 Xbox 360。 這個數值現在已經不再使用。

MacOSX 6

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

範例

以下範例示範如何使用該 PlatformID 類別來識別目前執行中的作業系統:

// 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.
*/
// This example demonstrates the PlatformID enumeration.
open System

let msg1 = "This is a Windows operating system."
let msg2 = "This is a Unix operating system."
let msg3 = "ERROR: This platform identifier is invalid."

// Assume this example is run on a Windows operating system.
let os = Environment.OSVersion
let pid = os.Platform
match pid with
| PlatformID.Win32NT
| PlatformID.Win32S
| PlatformID.Win32Windows
| PlatformID.WinCE ->
    printfn $"{msg1}"
| PlatformID.Unix ->
    printfn $"{msg2}"
| _ ->
    printfn $"{msg3}"
// This example produces the following results:
//     This is a Windows operating system.
' This example demonstrates the PlatformID enumeration.
Class Sample
   Public Shared Sub Main()
      Dim msg1 As String = "This is a Windows operating system."
      Dim msg2 As String = "This is a Unix operating system."
      Dim msg3 As String = "ERROR: This platform identifier is invalid."
      
      ' Assume this example is run on a Windows operating system.
      Dim os As OperatingSystem = Environment.OSVersion
      Dim pid As PlatformID = os.Platform
      Select Case pid
         Case PlatformID.Win32NT, PlatformID.Win32S, _
              PlatformID.Win32Windows, PlatformID.WinCE
            Console.WriteLine(msg1)
         Case PlatformID.Unix
            Console.WriteLine(msg2)
         Case Else
            Console.WriteLine(msg3)
      End Select
   End Sub
End Class
'
'This example produces the following results:
'
'This is a Windows operating system.
'

備註

使用 和 Environment.OSVersionOperatingSystem.Platform 屬性來取得 PlatformID 目前執行中的作業系統或開發平台的枚舉。 利用列 PlatformID 舉來判斷目前作業系統或開發平台是否支援您的應用程式。

你可以用每個 PlatformID 枚舉成員的底層整數值作為 PlatformIdSignTool.exe(符號工具) 工具的參數。

適用於