.NET and C# interview questions with answers on IL code, CLR, CTS, CAS

.NET and C# interview questions with answers on IL code, CLR, CTS, CAS


Hello everyone and welcome to the first section in .NET interview question preparation series In this section will try to cover important questions around IL code JIT, CLR, CTS and code access security i.e SAS Put a scope around you know what I am to cover in this video This video will not be demonstrating practicals. This video will not talk about how implement IL Code or how does it look like We have videos which actually cover practicals aspect of IL code, CLR, CTS, JIT Do go in to .NET fundamental section We have 5 great videos which talks about what is IL code CLR, CLS, JIT It talks about code access security, it talks about what are the changes made in code access security If you want to see practically all this things you can go and see this video over here My scope is more from interview aspect We will looking into more like what kind of questions come around this section, what kind of answers the interviewer expects and what kind of scenarios come during the interview In case you are interested in the practical demonstration videos step by step please go and see that section what I have just shown This section that is IL code, CLR, CTS, code access security look very basic Please note that you are either a junior you are either a senior,if you not able to answer these questions around this section the interviewer actually feels very uncomfortable about it I am not talking about people who with are less experience but people who are seniors who are seniors they are not able to answer questions around this I have seen lot of time people answering giving definitions of CLS in CTS and giving definitions of CTS in CLS What kind of questions ask around this section and how to answer them First question which definitely comes up is what is IL code Lot of people just answers full forms saying that IL code means intermediate language code When people ask you question you know what is WCF? don’t answer just full forms Go in depth and talk about that topic That does not give a good impression to the interviewer IL code is partially compiled code or a half compiled code The next question what the interviewer can ask here is Why is this IL code half compiled and it is not fully compiled When we talk about compiling what happen is you have source code here, this source code in C#, it is in C++ whatever it is There is a compiler who actually convert this source code into a machine language your Your computer understands only machine language When he compile this code into the machine language he takes various parameters while compiling for example what is a operating system for which his compilation should happen what is a hardware and different other configuration Think about a scenario where you have compiled a C# code, windows 7 operating system As per that instance the window 7 operating system property is taken that particular hardware where this window 7 is running That hardware properties are taken and optimal code is compiled as per that environment Take this compile code and if you try to run it in windows 2008 server or probably if you try to run it in windows 8 operating system it will run But it will not optimally run It will not run that performance benefits where it runs under Windows 7 You write a code in C# or in VB.NET the compiler converts this code into a half compiled format called as IL code During run time there one more entity called as the just in time compiler This just in time compiler comes in he takes all these input like what is a operating system, what is a hardware, what is a configuration Depending on these property he goes and he compiles optimal code for that moment During run time the compiler can figure out what is the operating system? what is a hardware? and compile optimal machine language as per that environment IL code is half compiled so during runtime the compiler can figure out what is a operating system you know what are the hardware configuration It can compile a optimal code as per that environment One other connected question which comes around IL code is who compile this IL code to machine language? It is done by somebody called as JIT JIT full form is just in time compiler One more question which can follow after JIT is so how does this JIT compile? Does it compile line by line or does it compile per file or per method JIT compiles the code in 3 ways one is per file other one is per method or function and last one is code fragment All of these 3 ways is all dependent on JIT we cannot control from outside saying that compile only this method That will depend completely on JIT he will take his own decision on how the applications is running Per file means here he will take complete C# file and compile it to a machine language Second one is per method so here he will take some method or function and compile only that method and function and save that compile code into in memory and the last one is code fragment where probably he can go and take 3 or 4 lines of code and compile that code into machine language How does the JIT compile to machine language he can do it file wise, he can do it method wise or he can do it code fragment wise There is one more rare question which comes around JIT and I personally feel that you know the question does not test anyone’s .NET knowledge The question comes in so let’s try to answer this question what are the different types of JIT that is available in .NET? There are three types of JIT which is available in .NET and This JITs you know can be categorized depending on the way they compile and the way do catching In normal JIT basically the compilation is done on demand basis, for example you have method 1 then only method 1will be compiled in case it is needed Once this method 1 is compiled the compile code is stored into cache i.e into RAM In Econo JIT is the same as normal JIT in other words here also the compilation is on demand basis but the compile code is not stored into cache or not stored into RAM In Econo JIT in case you have low memory if you don’t have lot of RAM for example mobile phones then this Econo JIT would be a better thing to use In normal JIT and Econo JIT the difference is only the one guy actually stores a compile code into cache and the other guy does not and finally there is something called is pre-JIT In pre-JIT there is no dynamic compilation there is full compilation This full compilation is done by this Ngen.exe You run Ngen.exe and then Ngen.exe will compile your complete .NET code into full machine language at that moment itself This is like a full compilation rather than the half compilation What are the difference types of JIT? There are three types of JIT one is a normal JIT, Econo JIT and pre JIT normal JIT Normal JIT does dynamic compilation and stores in memory Econo JIT does dynamic compilation but not stores in memory and pre JIT does full compilation by using Ngen.exe One more connected question around this rare JIT question is which comes is how can I force my compiler to use Econo JIT or a normal JIT The first thing you cannot it is internally decided by the compiler To use a normal JIT to use Econo JIT it is all internal Let say you are using some windows powered device window CE powered device or a mobile device where there is a memory crunch there is a RAM crunch then he will switch from normal JIT to Econo JIT By default he will try to use a normal JIT but in case you find said you know there is lot of memory crunch you will try to use normal JIT For pre JIT you can make a choice you can go and use this Ngen.exe and you can compile your code into full machine code and that moment itself Pre-JIT you can implement by using Ngen.exe but Econo JIT and normal JIT is All internally decided by the .NET compiler itself

19 thoughts on “.NET and C# interview questions with answers on IL code, CLR, CTS, CAS

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *