C# Tutorials - Herong's Tutorial Examples - v3.32, by Herong Yang
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) 2010 HerongYang.com. All Rights Reserved. using System; class HelloCLR { public static void Main() { Console.WriteLine("Hello 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# 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:
C:\herong>HelloCLR.exe 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.
Table of Contents
Logical Expressions and Conditional Statements
Visual C# 2010 Express Edition
►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
System.Diagnostics.FileVersionInfo Class
WPF - Windows Presentation Foundation