4

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?

Raúl Roa
  • 12,061
  • 13
  • 49
  • 64

2 Answers2

5

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;
Igor Brejc
  • 18,714
  • 13
  • 76
  • 95
3

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");
            }
    }
}
Jonathan Parker
  • 6,705
  • 3
  • 43
  • 54