Click here to Skip to main content
15,883,894 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int a = 10;
int b = 20;
int c = a + b;
Console.WriteLine("Sum of 10+20 is : " + c);
Console.ReadLine();
}
}
}
As i know c# compiler csc.exe convert this code to Byte code and JIT convert it to machine code. But when i press f5 in visual studio i want to know how the whole process done? Thanks in advance.
Posted
Comments
ZurdoDev 8-Oct-15 9:08am    
I suggest researching on MSDN. It'll be hard to explain the whole process here.

1 solution

Correct. The C# code is converted to MSIL, which is the assembly language that .NET's virtual machine understands. The MSIL is then compiled to machine code using Just-in-time compilation.

The process is done not just when you press F5. It is a very long process, when you build the project, at that moment C# source code is compiled to assemblies, the byte codes, then those assemblies are executed by .NET's virtual machine, using JIT compilation. It is not required to always use JIT to compile the MSIL to native code also. Because if you want to only compile the code (build it) and not run it, Visual Studio will only build the assemblies for you. Which are present under the /build/ folder.

It is a long process, when compiler compiles the code to MSIL, it also creates the meta-data. Because meta-data defines what your code is, how it should be executed and so on and so forth.

You should consider giving these MSDN a look:

1. Compiling to MSIL[^]
2. Compiling MSIL to Native Code[^]

These resources will help you understand the process. Also there is another method, which only provides you with the assembly code. Not the MSIL code. For that, debug your application, set a breakpoint to pause the application. Once application hits the breakpoint. Go to Debug --> and under Window, show Disassembly. It would show you the code for this! That code would be assembly language code. Read this MSDN guide for learning "How to: Use the Disassembly Window[^]".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900