Get Operating System Data and Version in C#

The following code snippet displays your Operating System's version, SP, and platform details by using the OperatingSystem object and its members.

The Version class and its properties Major, Minor, and Build represent the major, minor, and build numbers.

using System;


namespace OsVersionSample


    class Program


        static void Main(string[] args)


            Console.WriteLine("Operating System Detaiils");

            OperatingSystem os = Environment.OSVersion;

            Console.WriteLine("OS Version: " + os.Version.ToString());

            Console.WriteLine("OS Platoform: " + os.Platform.ToString());

            Console.WriteLine("OS SP: " + os.ServicePack.ToString());

            Console.WriteLine("OS Version String: " + os.VersionString.ToString());



            // Get Version details

            Version ver = os.Version;

            Console.WriteLine("Major version: " + ver.Major);

            Console.WriteLine("Major Revision: " + ver.MajorRevision);

            Console.WriteLine("Minor version: " + ver.Minor);

            Console.WriteLine("Minor Revision: " + ver.MinorRevision);

            Console.WriteLine("Build: " + ver.Build);






The output will look like following:



Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now