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# - 检测操作系统
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
