This article will revise 6 important c#/.NET interview questions
around concepts like IL code, just in time compiler, common type system; common
language specification, code access security and common language run time. Now
many .NET developers would frown at the article saying this is basic and
But what I have seen is
as you climb up the ladder you get engrossed in to projects, production issues,
or you start doing too many non-technical activities and you start forgetting
fundamentals. It’s not that you do not
know, you have just forgotten. And if you are not able to answer questions
around these topics how much ever senior you are, it sends a very bad message
to the interviewer.
IL code is a partially compiled code.
When a compiler compiles a code he takes in to consideration
things like operating system version, hardware etc and then compiles a
optimized code as per those environmental data.
Now let’s say your compiler has compiled an optimized code
as per “Windows 98” operating system. Now this code when run on windows server
will not probably run in a optimized manner.
So what .NET does it only compiles
the code partially. Later when the code runs the compiler kicks off, detects
the environment and does a fully optimized code compiler as per that operating
system and hardware.
Once the code is compiled it’s
maintained in cache. So the performance hit is only for the first time when
.NET application runs.
Who compiles IL code?
JIT (Just in time compiler) compiles the IL code to a fully compiled format.
Can we see IL code?
Yes, we can see the IL code by using the ILDASM tool.
In .NET there are lots of languages like C#, VB.NET, VF.NET etc. There can be situations when we want code of
one language to be called in other language. In order to ensure smooth
communication between these languages the most important thing is data type
compatibility. CTS (Common types system) ensures that data types defined in two
different languages get compiled to a common data type.
So “Integer” data type in VB6 and “int” data type in C++ will
be converted to System.int32, which is data type of CTS.
CLS is a subset of CTS. CLS is a specification or set of
rules or guidelines. When any .NET code adheres
to these set of rules it can be consumed by any .NET language.
For instance let’s say you have a c# class which has two
variables defined “I” and “i”. In other words one variable is in capital and
the other is in small.
Now this is perfectly valid in c# , but if this class is
consumed in VB.NET it will go for a toss. Because VB.NET is not case sensitive
and will not know which “I /i” variable to choose. So if you want this c# code
to be consumed in VB.NET you need to define variable with two different names.
This is one of the rules of CLS, that you should not have variable with same
name with case sensitive.
So in this way we have number of CLS rules which if followed
will ensure that your code can be consumed in any .NET compatible language.
CAS is the part of .NET security model which determines whether or not a
particular code is allowed to run and what kind of resources can the code
CLR (Common language run time) is the heart of.NET framework and it does 4
primary important things:-
CAS (Code Access security)
CV (Code verification)
IL to Native translation.
I have created this nice video here which talks about what kind of questions are asked in c# interviews. http://www.youtube.com/watch?v=3PXspVcSSKE
You can also visit my site c# and .NET interview questions where i have created range of videos on various topics of c# from interview preparation aspect.