Learn C Sharp Day 17

Lecture 17 : Learn C Sharp

IL Code :

  • IL code also known as Common intermediate language code or Microsoft intermediate language code.

  • IL code is a CPU independent partially half compiled code.

  • IL code (intermediate code) or half compiled code, it’s creates at compile time.

  • When this program will run at user system, this run time IL code is converted into machine code by JIT (just-in-time) compiler.

  • JIT Compiler converted IL Code into Machine Code.

Viewing IL code :
  • By using ILDASM tool(IL Disassembler open the Tool directly from the Visual Studio) we can view a IL code of a DLL or EXE.In order to view IL code using ILDASM, go to visual studio command prompt (CMD)and run “ILDASM.EXE”. Once ILDASM is running you view the IL code.

Example of IL Code with source code :

  • Let's demonstrate IL code example. Let's first create a simple windows-application in C# and a simple button.

  • In that button event add a simple basic code to display hello as shown in below source code.

  • For example, this very simple C# console app :

Program-

Output-

  • Now compile this above code and open visual studio command prompt. 

  • Inorder to open visual studio command prompt go the program files -> Microsoft 2010 -> Visual Studio Tools -> Find Visual Studio Command Prompt.

  • Click on file -> Open and select exe file or DLL file of above windows-application.

  • Select/Double Click button click event as displayed on ILDASM tool a editor will open which will display ILCODE as shown in below image.

JIT :

  • Just-in-time compiler on CLR takes the half partially compiled code and compile into machine specific on demand at application run time.

  • Just-In-Time compiler(JIT) is a part of Common Language Runtime(CLR) in .NET which is responsible for managing the execution of NET programming language. 

  • A language-specific compiler converts the source code to the intermediate language.

  • This intermediate language is then converted into the machine code by the Just-In-Time (JIT) compiler.

                      Working of JIT Compiler

  • The JIT compiler converts the Microsoft Intermediate Language(MSIL) or Common Intermediate Language(CIL) into the machine code this is done before the MSIL or CIL can be executed.

The following are the various types of JIT :

1)Pre-JIT Compiler :
  • In Pre-JIT compilation, complete source code is converted into native code in a single cycle (i.e. compiles the entire code into native code in one go)This is done at the time of application deployment.

  • And this compiler is always implemented in the Ngen.exe (Native Image Generator).

2)Econo-JIT Compiler :
  • In Econo-JIT compilation, the compiler compiles only those methods that are called at run time.

  • After execution the compiled methods are removed from memory.

3)Normal-JIT Compiler :
  • In Normal-JIT compilation, the compiler compiles only those methods that are called at run time.

  • After that, they are stored in the cache and used whenever they are called again.

  • Much of the disadvantages of the JIT compiler can be handled using the Ahead-of-time (AOT) compilation. This involves compiling the MSIL into machine code so that runtime compilation is not required and the machine code file can be executed nativly.

Strongly Typed Language :
  • C# is a strongly-typed language

  • It means we must declare the type of a variable that indicates the kind of values it is going to store, such as integer, float, decimal, text, etc.

Data Types :
  • The following declares and initialized variables of different data types :

  • Example :

                            1) string str = "Hello";
                            2) int n = 100;
                            3) float f = "10.2f";
                            4) char c = "A";
                            5) bool b = true;
                            6) double d = 1145222.555d;
                            7) decimal m = 1000.15m;
 Conversion :
  • The values of certain data types are automatically converted to different data types in C#.

Program-

Output-


Comments

Popular posts from this blog

Basic Concept In C Sharp Day 16

VS Code In JavaScript Day 6

ASP.NET MVC Interview Questions Part - II Day 26