HelloCLR.cs - Sample Application in C#

This section provides a tutorial example on compiling a sample program written in C# and executing it on the CLR (Common Language Runtime) of the .NET Framework.

Let's try to compile a simple application written in C# into a bytecode, so it can be executed by the CLR (Common Language Runtime) of the .NET Framework.

1. Enter the following source code in Notepad and save it file called, HelloCLR.cs:

// HelloCLR.cs
// Copyright (c) 2010 by Dr. Herong Yang, herongyang.com
using System;
class HelloCLR {
   public static void Main() {
      Console.WriteLine("Hello C# CLR {0}!", 
         Environment.Version.ToString());
   }
}

2. Compile the source code stored in HelloCLR.cs using the .NET Framework 4 C# compiler in command window:

C:\herong>\windows\Microsoft.NET\Framework\v4.0.30319\csc HelloCLR.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.

C:\herong>dir HelloCLR.*
     225 HelloCLR.cs
   3,584 HelloCLR.exe

The output of the "csc" command is the bytecode of the program in Intermediate Language stored in file, HelloCLR.exe, in the PE (Portable Executable) format.

3. When HelloCLR.exe is entered from a command line, Windows will invoke .NET CLR (Command Language Runtime) to perform the execution step:

C:\herong>HelloCLR.exe
Hello C# CLR 4.0.30319.239!

The CLR version number returned in the output shows that the program is executed in the .NET CLR virtual machine.

Last update: 2012.

Table of Contents

 About This Book

 1957 - FORTRAN Language Developed by IBM

 1970 - UNIX Operating System Developed by AT&T Bell Labs

 1971 - FTP Protocol Created by Abhay Bhushan

 1972 - C Language Developed by Dennis Ritchie

 1976 - vi Text Editor Developed by Bill Joy

 1977 - Apple II Designed by Steve Jobs and Steve Wozniak

 1977 - The Bourne Shell Developed by Stephen Bourne

 1978 - The C Shell Developed by Bill Joy

 1978 - Bash (Bourne-Again Shell) Developed by Brian Fox

 1979 - The Tcsh (TENEX C Shell) Developed by Ken Greer

 1983 - "Sendmail" Mail Transfer Agent Developed by Eric Allman

 1984 - Macintosh Developed by Apple Inc.

 1984 - X Window System Developed a MIT Team

 1991 - WWW (World Wide Web) Developed by Tim Berners-Lee

 1991 - Gopher Protocol Created by a University of Minnesota Team

 1995 - Java Language Developed by Sun Microsystems

 1995 - PHP: Hypertext Preprocessor Created by Rasmus Lerdorf

2002 - .NET Framework Developed by Microsoft

 Introduction of .NET Framework

HelloCLR.cs - Sample Application in C#

 HelloCLR.vb - Sample Application in VB

 References

 PDF Printing Version