Let's say you write an app in C#, VB, anything with .NET When you hit build, does it really compile your code? I thought so until I started using redgates reflector on some of my assemblies and saw my code verbatim. I would have expected loops to be unrolled and another plethora of optimizations, instead nothing.
So when does the compilation actually happen? I think when it is built, code become IL (Intermediary Language) and when execution occurs, it is loading in the CLR? Is it optimized during CLR only and never at build time?
When you compile in VS
When you execute:
I post the answer here too as the other question was not really about this...
It is compiled down to IL at, well, compile time. Reflector's magic is that it "understands" the IL and converts it back into c# (or VB.NET or whatever. Look under the Options menu in Reflector and you can view the assembly in any format, including the IL).
In Reflector, you actually are not seeing your original code. You are seeing a translation of the IL into c#. Most of the time that will be very similar to what you wrote, but there are some telltale signs - for example, find a place where you implemented an auto-property:
string MyProperty {get;set;}
And you'll see what that actually compiles to, which is something like this:
public string MyProperty
{
[CompilerGenerated]
get
{
return this.<MyProperty>k__BackingField;
}
[CompilerGenerated]
set
{
this.<MyProperty>k__BackingField = value;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With