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 109 views
1 answer 115 views
1 answer 116 views
1 answer 116 views
1 answer 124 views
1 answer 82 views
1 answer 110 views
...