The first Application

Compiling and running

Before we can run our example, we have to compile it to the Common Intermediate Language, or CIL used by the Mono and .NET runtimes. Once you have installed Mono, you can type the following at the command-line: You can pass command-line parameters to the compiler to change the name of the output file, embed debugging symbols in the generated file, and more. You can learn more about using the Mono C# Compiler in section 7.2 of The Mono Handbook.

The Mono C# compiler is command-line compatible with the Microsoft .NET Framework C# compiler. If you were entering examples from a Microsoft .NET tutorial or .NET centric book, generally you could substitute mcs for any mention of csc, and it should work OK.

Type this source in your favourite editor (like notepad) and save it as "hello.cs" somewhere.

Now open a new console window, change to that directory and type:

mcs hello.cs
This command produces a file named HelloWorld.exe in the current directory. This file contains our program, ready to run.
You can execute your first program in C# by typing:
mono hello.exe