C# compiled in mono - Detect OS(以单声道编译的 C# - 检测操作系统)
问题描述
我正在尝试让 C# 应用程序在 OSX 下运行,这并不是完全没有痛苦的.为了在短期内解决一些问题,我正在考虑在 OSX 中运行时设置一些特定的规则.
I am trying to get a C# app running under OSX which is not exactly pain free. To work around some of the issues in the short term, I am thinking of setting up some specific rules when it is running in OSX.
但是...我可以使用什么来确定应用程序是在 Windows 还是 OSX 下运行?
But... What can I use to determine whether the app is running under Windows or OSX?
推荐答案
来自 Mono wiki(根据我的经验,OSX 被识别为 Unix):
From the Mono wiki (in my experience, OSX is identified as Unix):
int p = (int) Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) {
Console.WriteLine ("Running on Unix");
} else {
Console.WriteLine ("NOT running on Unix");
}
或者
string msg1 = "This is a Windows operating system.";
string msg2 = "This is a Unix operating system.";
string msg3 = "ERROR: This platform identifier is invalid.";
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;
}
这篇关于以单声道编译的 C# - 检测操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:以单声道编译的 C# - 检测操作系统
基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01