2011-08-16 43 views

回答

18

從單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類型,註定在未來失敗。

長和短,只是不。

+0

感謝Adam。我只問,因爲我可能需要解決一個錯誤。 – Simon

+0

@西蒙沒有問題 - 有時甚至你顯然不應該做的東西是必需的。 –

+0

原來這是一個重複:)但你仍然有一個很好的答案 – Simon

11

mono porting guide

public static bool IsRunningOnMono() 
{ 
    return Type.GetType ("Mono.Runtime") != null; 
} 
相關問題