Sunday, November 29, 2015

MonoDevelop/C#: get the current running Common Language Runtime verion, with the Environment.Version property.

Read the Environment.Version Property to gets a Version object that describes the major, minor, build, and revision numbers of the common language runtime.

For the .NET Framework Versions 4, 4.5, 4.5.1, and 4.5.2, the Environment.Version property returns a Version object whose string representation has the form 4.0.30319.xxxxx. For the .NET Framework 4.6, it has the form 4.0.30319.42000.

Example:
using System;

namespace HelloWorldCsharp
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.WriteLine ("Hello World!");

            /*
             * For the .NET Framework Versions 4, 4.5, 4.5.1, and 4.5.2, 
             * the Environment.Version property returns a Version object whose 
             * string representation has the form 4.0.30319.xxxxx. 
             * 
             * For the .NET Framework 4.6, it has the form 4.0.30319.42000.
             * 
             * ref: https://msdn.microsoft.com/en-us/library/system.environment.version(v=vs.110).aspx
            */
            Console.WriteLine("Version: \t" + Environment.Version.ToString());
            Console.WriteLine("(Major): \t" + Environment.Version.Major.ToString());
            Console.WriteLine("(Minor): \t" + Environment.Version.Minor.ToString());

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}