PlatformID 枚举

定义

标识程序集所支持的操作系统(或平台)。

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

字段

MacOSX 6

操作系统为 Macintosh。 Silverlight 返回此值。 在 .NET Core 上,将替换为 Unix

Other 7

任何其他操作系统。 这包括浏览器 (WASM)。

Unix 4

操作系统为 Unix。

Win32NT 2

操作系统为 Windows NT 或较新的版本。

Win32S 0

操作系统为 Win32s(Win32 子集)类型。 不再使用此值。

Win32Windows 1

操作系统为 Windows 95 或 Windows 98。 不再使用此值。

WinCE 3

操作系统为 Windows CE。 不再使用此值。

Xbox 5

开发平台为 Xbox 360。 不再使用此值。

示例

以下示例演示如何使用 PlatformID 类标识当前正在执行的操作系统:

// This example demonstrates the PlatformID enumeration.
using namespace System;
int main()
{
   String^ msg1 = L"This is a Windows operating system.";
   String^ msg2 = L"This is a Unix operating system.";
   String^ msg3 = L"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;
   }
   return 1;
}

/*
This example produces the following results:

This is a Windows operating system.
*/
// 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.OSVersion使用和OperatingSystem.Platform属性获取PlatformID当前正在执行的操作系统或开发平台的枚举。 使用 PlatformID 枚举来帮助确定当前操作系统或开发平台是否支持应用程序。

可以使用每个 PlatformID 枚举成员的基础整数值作为 PlatformId SignTool.exe (符号工具) 实用工具的参数。

适用于