Before you start
C# - an interpreted or compiled language?
Now, what is C#. Interpreted or compiled?
The answer is: both.
To understand how this can happen and why this is a Good Thing I
need to explain how Mono works.
All Mono languages, including C# are compiled with a compiler by
the developer. However the output is not a native binary file, but
a special bytecode, called CIL (or IL or MSIL). This bytecode is
unreadablebut can not be executed by the computer. It is important
to understand, that all Mono languages are compiled to CIL, C# as
well as MonoBasic.
The binary file will later be interpreted at runtime by the Mono
Executing Engine on the users computer. You may ask now: If it is
interpreted anyway, where is the point in compiling it to bytecode
first?
The compiling has several consequenses:
- The code is protected for closed source programs
- The code can be optimized by the compilers, so it can be
interpreted much, much faster. In fact the executing is that fast,
that the interpreter is called JIT (just-in-time-compiler). Unlike
an interpreter it does generate real native code.
- This is the secret of language independence: All language are
compiled to CIL and thus are equal. If the compiling step would be
skipped the Mono Execution engine could only execute C# code or
maybe with special support Basic code, but not a new language
without changing mono itself.
- Through the interpreting special security can be applied
- The interpreter can offer things like garbage collection
- The applications are still multi platform
- Compilers need not porting if the Mono Core is ported
Mono does ship a C# compiler (mcs) and an execution engine (mono).