Getting CLR (Common Language Runtime) Information

This section provides a tutorial example on how to use execution environment class, System.Environment, to retrieve information about the CLR (Common Language Runtime).

When you run an executable file generated from the C# compiler, you are actually invoking the .NET CLR (Common Language Runtime) to run it. CLR is a virtual machine that runs bytecode generated by C#, VB.NET or orther .NET compilers.

The System.Environment class can also be used to get version information of the CLR used to the run the application. Here is an tutorial example program, ShowCLR.cs:

// ShowCLR.cs
// Copyright (c) 2015, HerongYang.com, All Rights Reserved.

using System;
class ShowCLR {
   public static void Main() {
      OperatingSystem os = Environment.OSVersion;
      Console.WriteLine("Operation system: {0}", os.ToString());

      Version clr = Environment.Version;
      Console.WriteLine("Common language runtime: {0}", 
         clr.ToString());

      Console.WriteLine("Memory size: {0} bytes", 
         Environment.WorkingSet);
   }
}

I compiled this example program with .NET Framework 4.0 SDK and got this output:

C:\herong>\Windows\Microsoft.NET\Framework\v4.0.30319\csc ShowCLR.cs
Microsoft (R) Visual C# Compiler version 4.6.1055.0
for C# 5

C:\herong>ShowCLR
Operation system: Microsoft Windows NT 6.1.7601 Service Pack 1
Common language runtime: 4.0.30319.42000
Memory size: 6094848 bytes

As a comparison, here is the output from NT Framwork 2.0 SDK:

C:\herong>\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc ShowCLR.cs

C:\herong>ShowCLR.exe

Operation system: Microsoft Windows NT 5.1.2600 Service Pack 3
Common language runtime: 2.0.50727.3615
Memory size: 6189056 bytes

Table of Contents

 About This Book

 Introduction of C# (C Sharp)

 Data Type and Variables

 Logical Expressions and Conditional Statements

 Arrays and Loop Statements

 Data Type Features

 Floating-Point Data Types

 Passing Parameters to Methods

Execution Environment Class

 Visual C# 2010 Express Edition

 Class Features

 C# Compiler and Intermediate Language

 Compiling C# Source Code Files

 MSBuild - Microsoft Build Engine

 Memory Usages of Processes

 Multithreading in C#

 Async Feature from C# 5

 System.IO.FileInfo Class

 System.Diagnostics.FileVersionInfo Class

 WPF - Windows Presentation Foundation

 Partial Classes and Partial Methods

 Outdated Tutorials

 References

 PDF Printing Version