C# Code Execution Process | Question & Answers


csharp Code Execution Process

C # code execution process involves 2 main steps. the steps are 

        1. Compile-time Process (CSC.exe)
        2. Run Time Process (CLR)

Compile Time Process :

  • In This article, I am going to explain one c# program. first, create a program and name it "hello.cs".
  • and save in any of the drivers on your computer or pc.
  • Next, open the program in any one of the editors, and my suggestion uses Microsoft visual studio.
  • now Compile the program
  • whenever we compile the program then one ".exe " file will be generated

Run Time Process :

How the execution flow happens when you compile and execute the c# program?

  • CLR means Common Language Runtime takes care of all about the execution process.
  • So whenever the program compiles then the immediate step is to load the program into CLR.
  • CLR search for static variables and allocate the memory for static variables 
  • CLR search for methods and loads into Method area as shown in the above image
  • CLR searches for "static void main" and loads into the execution engine.

Simple Explanation :

        • Create the c# program
        • compile the c# program
        • load into CLR
        • execute the program

In-depth Explanation :

  1. Create the c# program in any local machine and save it with any name
  2. load the program into Visual Studio Editor
  3. Compile the C# program 
  4. CSC compile will check the Syntax errors, If there are no syntax errors then it will generate the ".EXE" file.
  5. now onwards CLR take cares
  6. the program loads into CLR and the ".exe" file internally contains MSIL code.
  7. MSIL code did not understand by OS.
  8. CLR has one component that is Just In Time(JIT).
  9. JIT will take care of the conversion from MSIL code to Native code.
  10. now JIT converts the MSIL code to OS understandable language.
  11. finally, it generates the Output.

Simple Question to Understand.

    1) Where the static variable stored in memory?

    A) in Stack

    2) When the memory is allocated for static variables?

    A) whenever the class loads into CLR.

    3) Where all the methods Loaded?

     A) Method Area in RAM.

    4) Where all the methods Executed?

     A)  Execution Engine

No comments: