I need a very small C# library that would tell me on what operating system my C# program is running.

I don't need the OS version number, just something very general, for instance I would be happy with one of:

Windows, Mac, Linux, Android, iOS


  • Open Source, ideally Public Domain
  • Downloadable easily as DLL

None of the solutions at https://stackoverflow.com/questions/10138040/how-to-detect-properly-windows-linux-mac-operating-systems are robust+easy enough.

1 Answer 1


C# itself actually provides a method to detect what operating system you are running at a basic level. All of the OS' it can detect can be found in the link. Is this what you were looking for?

OperatingSystem os = Environment.OSVersion;
PlatformID     pid = os.Platform;
switch (pid) 
    case PlatformID.Win32NT:
    case PlatformID.Win32S:
    case PlatformID.Win32Windows:
    case PlatformID.WinCE:
        Console.WriteLine("I'm on windows!");
    case PlatformID.Unix:
        Console.WriteLine("I'm a linux box!");
    case PlatformID.MacOSX:
        Console.WriteLine("I'm a mac!");
        Console.WriteLine("No Idea what I'm on!");
  • 2
    Apparently the value is sometimes Unix even for MacOS though: stackoverflow.com/questions/10138040 (linked from my question too)
    – Nicolas Raoul
    Commented Nov 7, 2014 at 11:40
  • @Nicolas Raou: That's because OSX I Unix, too. Commented Jan 13, 2020 at 15:17
  • @StefanSteiger While it is technically true, such a value is not as informative as what the question asks for. If there is a PlatformID.MacOSX then a solution that gives PlatformID.MacOSX for all MacOS systems would be better.
    – Nicolas Raoul
    Commented Jan 14, 2020 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.