1. What is IL or MSIL?
IL is acronym for Intermediate language; is also known as MSIL or CIL (Common Intermediate Language). All .NET source code is compiled in IL and IL is then converted into machine code at run time by JIT (Just-In-Time) compiler.
2. What is CLR?
Common language runtime is the heart of the .NET framework. CLR is responsible for:
a) Garbage collection: GC runs automatically in .NET framework, manages the memory and removes the memory leaks when some object is not in use.
b) Code access security: CAS takes care of rights of program execution as per security configuration of machine.
c) Code verification: It prevents the code to perform illegal operations like assigning invalid memory locations.
d) IL to native translation: CLR converts the IL into the machine code.
3. What is CTS?
.NET framework supports more than one languages in a single project. In order to make two languages run smoothly, CTS (common type system) helps CLR. For example, integer in VB and int in C# are not compatible so interfacing between them is difficult. For such scenario, CTS converts both the data types VB - integer and C# - int into System.Int32 and make them similar for machine.
4. What are the differences between managed and unmanaged code?
Managed code is the code developed with .NET framework is a managed code because CLR has the control over it. Managed code is compiled to IL despite of machine code. IL is handled and converted to machine code by CLR. So, CLR handled Garbage collection, Code Security etc.
Un-managed code is the code developed outside of .NET framework and CLR doesn't have control over it rather it is handled and executed directly by operating system. Unmanaged code is complied to machine code directly. So system is not responsible garbage collection, code security etc. unmanaged code handles object disposing and other things if developer has written the code to do so.
5. What are the differences in namespaces and assembly?
- Namespace is logical grouping of classes while assembly is physical grouping of classes, namespaces, interfaces etc.
- Assembly contains the metadata (compiled code) so they are secure like dll files.
- Assembly can have version but namespace cannot have.
Note: Namespace is very important to categorize the classes, functions etc. Namespace allows us to create a class with a name which is already being used by other namespace or .NET framework's predefined classes.
6. What is GAC?
GAC (Global assembly cache) is used to keep the assemblies which can be used by more than one application of that machine.
So if the application or assembly has to be shared among several applications, we register them in GAC.
Or else sometimes when you want to add some addtional security to the assembly like only the system administrator should be able to modify and remove that assembly, then also we register them in GAC. Working on payment gateway is the best example of this.
7. What is JIT? What are the different types of JIT compiler?
JIT is Just-in-time compiler. It coverts compiled code (IL) to machine code on demand of application at run time. There are 3 types of JIT:
1) Pre-JIT: It compiles complete source code into native code in a single compilation cycle.
2) Econo-JIT: It compiles only those methods which are called at runtime and these are removed from cache when they are not required.
3) Normal-JIT: It also compiles only those methods which are called at runtime and saved in cache. When system needs to call them again, the compiled code from cache is used for execution.
8. What are value types and reference types?
These are the types of variable we have in any application programming language.
Value types contain data directly which is allocated on stack in memory while reference types contain a reference of the value's memory address and it is stored on a heap.
All value type variables have their own copy of data thats why operations on one variable do not affect the others. Reference type variables can refer to the same memory address (object). SO if we change the value of one reference type is might affect other also.
9. What is boxing and unboxing?
These are the concepts of converting two data type into each other.
Boxing allows any value type to be converted into the object or reference type implemented by that value type.
Unboxing is opposite of boxing and in this value is copied from an instance (stack) to an appropriate storage location (heap). It means, it allows to convet any object to value type.
int i = 9;
object obj = new object();
i = 99;
obj = i; //Boxing
i = (int)obj; //Unboxing
10. What are the differences between VB and C#?
VB.Net compiles the code in background parallel to deveopment hence it is good for small applications but not good for very big applications. For big project in VB, development environment slows down.
VB has 'With' and 'AndAlso' key words. So we reduce the code to be written.
VB doesn't have 'Operator overloading' while C# is having this.
VB has optional parameter while C# doesn't have this. To achieve the same, we have to go with function overloading in c#.
11. What is difference between .ToString() and Convert.ToString()?
ToString() does not handle NULL values while converting. Convert function handles 'NULL' values also. So, it is good to use Convert.ToString() always to avoid 'Null reference exception.' But for the obvious places which cannot be NULL, we should use ToString() because it is faster.