可能重複:
How to detect which .NET runtime is being used (MS vs. Mono)?如何告訴我的代碼在Mono上運行?
在.NET道瓊斯我怎麼知道我的代碼在運行單?
可能重複:
How to detect which .NET runtime is being used (MS vs. Mono)?如何告訴我的代碼在Mono上運行?
在.NET道瓊斯我怎麼知道我的代碼在運行單?
從單FAQ:
http://www.mono-project.com/FAQ:_Technical
下面是直接從該鏈接:
我怎樣才能檢測是否是在運行單?
具有依賴於底層運行時的代碼被認爲是 錯誤的編碼風格,但有時候這樣的代碼對於解決運行時錯誤是必需的。檢測單聲道所支持的方式是:
using System;
class Program {
static void Main()
{
Type t = Type.GetType ("Mono.Runtime");
if (t != null)
Console.WriteLine ("You are running with the Mono VM");
else
Console.WriteLine ("You are running something else");
}
}
任何其他劈,如檢查的基礎類型System.Int32 的或其他corlib類型,註定在未來失敗。
長和短,只是不。
public static bool IsRunningOnMono()
{
return Type.GetType ("Mono.Runtime") != null;
}
(我被告知添加評論,對不起)檢查color = D(我知道這是厚臉皮,但是meh) – Coops