How to get the current OS name and version in C#

1 Answer

0 votes
using System;
using System.Runtime.InteropServices;

class Program
{
    static void Main()
    {
        // Get the OS description (e.g., Windows, Linux, macOS)
        string osDescription = RuntimeInformation.OSDescription;

        // Get the OS architecture (e.g., x64, ARM)
        string osArchitecture = RuntimeInformation.OSArchitecture.ToString();

        Console.WriteLine($"Operating System: {osDescription}");
        Console.WriteLine($"Architecture: {osArchitecture}");
    }
}


 
/*
run:
     
Operating System: Unix 6.6.72.0
Architecture: X64
 
*/

 



answered Mar 27, 2025 by avibootz

Related questions

1 answer 95 views
1 answer 100 views
1 answer 102 views
1 answer 105 views
1 answer 111 views
1 answer 74 views
1 answer 94 views
...