Is C# code compiled to native binaries?
Asked Answered
M

6

21

I know that Java code is compiled into byte-code, that is executed by the JVM.

What is the case with C# ? I have noticed that applications written in C# have the .exe extension what would suggest they are native machine instructions. but is it really so ?

Morganmorgana answered 25/9, 2012 at 13:0 Comment(2)
This should explain. en.wikipedia.org/wiki/List_of_CLI_languagesFissionable
With ngen (alike Java with jit)Ary
T
31

No.

Like Java, C# is compiled to an intermediary language (called MSIL or CIL).

Unlike Java, the IL is stored in EXE files which have enough actual EXE code to show a dialog box asking users to install .Net.

Tutelary answered 25/9, 2012 at 13:1 Comment(9)
Mm. Bit confusing to just say "No" to "Is C# code compiled". Obviously, it is compiled. Into CLI instructions. Just not (directly) into native code. Obviously, in the end they are (just-in-time) compiled to native code, anyways.Porscheporsena
@sehe: I'm saying "no" to the last line in the question.Tutelary
I've edited the question title to avoid the mismatch there :)Porscheporsena
It's not that simple. There is ngen and GAC.Lewse
Okay. Does C# then take any advantage of being stored in an EXE or being developed by the same company as the OS? Short: is C# faster than Java?Morganmorgana
@Morganmorgana it is as fast as it needs to be. If you are having a slow down, run a profiler and identify the problem, don't just blame the language.Eusebioeusebius
@Lewse So.. is it possible to compile C# to native binary? For instance, in Visual Studio?Morganmorgana
@Queequeg, use ngen for pre-compiling your assemblies into native code.Lewse
But can it be a default behavior, can I really make a standalone executable that will run on a Windows machine that doesnt have .net installed?Morganmorgana
A
6

C# compilation is done in these two steps :

1. Conversion from C# to CIL by the C# compiler

2. Conversion from CIL to instructions that the processor can execute.

A component (just in time) performs this compilation at run time from CIL to machine code

Anthonyanthophore answered 25/9, 2012 at 13:12 Comment(0)
H
6

What that .exe is supposed to tell you is that the file is executable. C# is compiled into bytecode, just as java is, but .NET wraps this in a CLR executable.

Look here for a more in depth look at CLR executable http://etutorials.org/Programming/.NET+Framework+Essentials/Chapter+2.+The+Common+Language+Runtime/2.2+CLR+Executables/

Hydroplane answered 25/9, 2012 at 13:12 Comment(1)
The term Portable Executable is not just specific to .NET.Octosyllabic
B
5

c# code is compiled to MSIL. it likes java bytecode. msil will be convert to machine isntrctions at runtime.

Brothers answered 25/9, 2012 at 13:2 Comment(0)
V
3

C# code is compiled to MSIL, MSIL is taken care by .NET CLR

Voncile answered 25/9, 2012 at 13:5 Comment(0)
B
0

There is also a project that allows compilation of C# to standalone binary executables: CoreRT

Begun answered 13/2, 2020 at 8:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.