Hello OS with C# & mono?

别等时光非礼了梦想. 提交于 2020-01-03 15:58:32

问题


Is there a way to identify in which OS we are running mono, with C# code?

Some sort of Hello World, but instead of using a fixed string as an output use the current OS?


回答1:


Try System.Environment.OSVersion

You can also detect if your code is run under Mono or MS.NET:

if (Type.GetType("Mono.Runtime") != null) 
{
    // we're on Mono
    IsMono = true;
} 
else
    IsMono = false;



回答2:


This link: http://mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F

Give this code:

using System;

class Program {

    static void Main ()
    {
            int p = (int) Environment.OSVersion.Platform;
            if ((p == 4) || (p == 6) || (p == 128)) {
                    Console.WriteLine ("Running on Unix");
            } else {
                    Console.WriteLine ("NOT running on Unix");
            }
    }
}


来源:https://stackoverflow.com/questions/692410/hello-os-with-c-sharp-mono

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!