为啥要判断操作系统,C#不是微软的作品嘛,Windows下的,是判断版本?不是的,还有个东西叫mono。
using System;
PlatformID pid = Environment.OSVersion.Platform;
其中PlatformID是一个枚举类型,不看不知道,C#还是蛮厉害的
public enum PlatformID
{
//
// 摘要:
// 操作系统为 Win32s(Win32 子集)类型。Win32s 是运行于 Windows 16 位版本上的层,它提供对 32 位应用程序的访问。
Win32S = 0,
//
// 摘要:
// 操作系统为 Windows 95 或较新的版本。
Win32Windows = 1,
//
// 摘要:
// 操作系统为 Windows NT 或较新的版本。
Win32NT = 2,
//
// 摘要:
// 操作系统为 Windows CE。
WinCE = 3,
//
// 摘要:
// 操作系统为 Unix。
Unix = 4,
//
// 摘要:
// 开发平台为 Xbox 360。
Xbox = 5,
//
// 摘要:
// 操作系统是 Macintosh。
MacOSX = 6
}
用的windows7,结果是Win32NT = 2。