Compilation - Converting Source Code to Bytecode

This section provides a tutorial example on how to compile a C# source code into a .NET Intermediate Language bytecode using the .NET C# compiler.

Let's review the C# compilation step with a simple C# source code.

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

// HelloCLR.cs
// Copyright (c) 2015,, All Rights Reserved.
using System;
class HelloCLR {
   public static void Main() {
      Console.WriteLine("Hello CLR {0}!", 

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# Compiler version 4.6.1055.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

C:\herong>dir HelloCLR.*
     237 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.

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


Hello CLR 4.0.30319.42000!

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

Last update: 2015.

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 and Running C# Programs

Compilation - Converting Source Code to Bytecode

 .NET Intermediate Language Disassembler

 CLR Based PE (Portable Executable) Files

 Disassembling Intermediate Language Bytecode

 Assembling Intermediate Language Source Code

 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


 PDF Printing Version