.Net Interview Questions for Fresher/Experienced

This post contains the most popular interview questions for the .net framework. If you are a .net developer you must have faced these questions in your interviews or in your future interview. Here, I have listed 30 important interview questions with answers. Hope it will be a good refresher for the guys, preparing for an interview.

Q1.The key component of the .net framework?

The main component of .net frameworks are :
  • CFL – Class framework library. Such as System.IO, System.Data etc
  • CLR – Common Language Runtime.
  • Other application templates related component/library which resides on top of CFL and CLR such as windows application, WCF, WebAPI related library.

Q2.Features of .net framework?

  • Multiple Language Support
  • Automatic Garbage Collector
  • Type Safety
  • Security
  • Rich CLR
  • Portability
  • Legacy Support

Q3. What is IL – Intermediate Language?

IL stands for Intermediate Language. It is similar to assembly language code which will be converted to byte code and assembly will be created.
IL makes .net framework language independent. All .Net supported language should generate the same IL code.

Q4. Source code execution flow?

  1. Source code first converted to IL by CLR.
  2. IL converted to byte code[numeric code] and assembly will be created.
  3. Assembly/Byte code is then converted by JIT and native code will be generated
  4. Native code will be executed by the operating system.

Q5. What is CLR? What are the features of CLR?

CLR is the runtime environment for the .net framework. CLR is indeed the heart of .net framework because of its features/tasks. CLR handles several critical tasks for the .net framework. Some of the tasks are:
  • Type Safety
  • Thread Management
  • Input/Output Management
  • Memory Management- Garbage Collection
  • Converting Source code to IL and IL to byte code.
  • Security
  • Interoperability 

Q6. What are CTS and CLS? Difference between CTS and CLS?

  • Both CTS and CLS is part of CLR.
  • CTS acronyms for the common type system. CTS defines how the data types are created and managed in the .net run-time environment. It also says that all the data types present in various .net supported language should adapt to the same data structure. Such as, While converting vb.net code to csharp.net, integer of vb.net should be shown as Int32 to C# by IL.
  • CLS acronyms for common language specification. CLS considered as language guidelines for the third party language developer which targets .net frameworks. Its guidelines for making third party language as CLR compliance. CLS says as guidelines that all .net supported language has to generate exact same type of IL when compiled.

Q7. What is JIT? Types of JIT?

JIT stands for the JUST IN TIME compiler. This is used for converting Assembly/Bytecode to native code. It’s part of CLR.
There are 3 types of JIT available :
  • Pre JIT – It compiles and cached whole code at once and will not compile on demand. This is done by using a utility named ngen.exe.
  • Normal JIT – It compiles the required IL Code and cached that only part. 
  • Econo JIT – This works the same as normal JIT but not caching any part of code. Used for small handheld devices having memory constraints.

Q8. What is NGEN utility?

NGEN utility is used for caching whole code at once and used the cached image of compiled code thereafter. It minimizes the frequent compilation of code on every execution.

Q9. What is assembly? Type of assembly? What is manifest?

Q10. What is a strong name and how to signed strong name to the assembly?

Q11. Strongly typed and weakly typed assembly? 

Q12. How to add the assembly to GAC?

Q13. Where does GAC locate in the system?

Q14. GAC – Use of GAC?

For Q9,Q10,Q11,12,13,14 : Please see this post – https://techdiksha.com/gac-global-access-cache-dll-hell-problem/

Q15. What is a satellite assembly?

Generally, assembly is language-neutral i.e it doesn’t contain cultural information. But when the assembly is localized based on language such assembly is called satellite assembly i.e Cultural information: en-US, etc.

Q16. Compare namespace and assembly?

Assembly can be considered as the physical grouping of logical units whereas Namespace logically groups the classes.
Assembly can have contains multiple namespaces

Q17. What is ILASM & ILDASM ?

Assembly is generated by either a compiler or a utility called ILASM (IL Assembler) that is shipped with the execution environment.

Assembled IL can be disassembled into code again using ILDASM(IL Disassembler). There are other tools such as .net reflector that can decompile IL into the high-level language target for reverse engineering.

Q18. What is the delay signing?

Generally, in the development process, Actual private key for signing the assembly is not exposed to the team or access to those key is with some limited person/team. 
                     Also, These private key might get from some other signing authority, which may take time to procure and made available. 
So, Initially, we signed the assembly with public key- strong name, which keep placeholder [space] inside Portable Executable file for strong name signature, but defer/delay the actual/ real signing til later stage (generally just before delivering the assembly).
                      When we use the public-key strong name for signing, we also enable delay signing for that assembly. We do annotation as such in AssemblyInfo.cs :
Verification must be turned off for that signature as the assembly not having a valid required signature for a strong name. It can be done by adding the –Vr option together with the Strong Name utility.
The below example disable the verification of an assembly named  myAssembly.dll.             
 sn –Vr ownAssembly.dll
In Later stage, usually, just before delivering, organization’s signing authority does the actual strong name signing by using -R option in strong name utility.
 sn -R ownAssembly.dll sgKey.snk – This command helps to sign the strong name of sgKey.snk key pair to the assembly called myAssembly.dll.

Q19. DLL Hell problem & how GAC solve DLL hell problem?

Q20. What is Type safety?

Type safety is a language feature which promotes the robustness of the program. It defines several rules for object type verification, value assignment, range verification etc. For example : 
– one data type can not be assigned to other data types if they are not compatible [different]. For example, the string should not be assigned implicitly to an int data type or Customer data type should not be assigned to the Order data type.
– int variable should be assigned before use.
– checking of upper bound for the array.
C# is type-safe language as it does compile-time type verification for the object by using metadata information. It increases robustness and consistency. 

Q21. What are Upcasting and Downcasting?

C# Support Upcasting and Downcasting.
Upcasting means small-sized data type being assigned to large-sized data types. For example, int data type can be assigned to long implicitly. 
⧭ Upcasting can be implicit. 
⧭ Upcasting does not have any data loss.
Downcasting means large-sized data type is assigned to the small-sized data type. for example, long datatype assigned to int.
⧭ Downcasting may lead to data loss. For example, when we convert double 11.15 to int, the decimal point will be lost.

Q21. Managed and Unmanaged code?

Managed code is the source code which runs under the supervision of CLR means, CLR keeping track of memory allocation-deallocation, type safety of the managed object. For such a managed object, CLR facilitates automatic garbage collection.

Unmanaged code: code which does not run under the CLR. Means, these objects are not a native object of CLR, such object is run directly by the OS. In .net we use such object by some wrapper classes, such as database connection object, win32 related object, file streams etc. These objects are not managed by CLR, developers need to takes care of the memory management such as deallocation, overflow, leaks etc.

Q22. How does .net do automatic garbage collection?
Q23. What is the generation and type of generation? Why GC use generation?

For all managed code, .net creates a heap to keep track of objects. Called Managed Heap. These Managed heap further categorized in the generation. Generation is segregation of managed heap based on the longevity of the object.

Generation : 

.net have Generation 0 , Generation 1 and Generation 2.
Here, Generation 0 Contains short-lived object such as temporary variable and Generation 2 consists of a long-lived object such as static object.

Why Generation:

For efficient memory management. GC visits Generation 0 frequently than Generation 1 because generally, we have the more short-lived object in code than the long one. 

Q24. Can we call GC explicitly by code?

YES, We have method GC.Collect()

Q25. When does garbage collector trigger? Or How to trigger the garbage collector?

Below is the scenario when the garbage collector gets triggered :
⧭ When memory for the generation gets exhausted.
⧭ When Application gets closed
⧭ When we call GC.Collect()

Q26. Difference between Finalize and Dispose?

  1. Finalize is un-deterministic i.e, generally, we do not know when GC will trigger. Whereas, Dispose we call it explicitly by code all the time.so, it’s deterministic.
  2. We implemented finalize through using Destructor(~) with class Whereas we define Dispose() by implementing the IDisposable interface.
  3. Dispose is used for freeing the unmanaged resources such as DB connection, file etc Whereas, Finalize is used for managed resources, however, we can use Dispose and Finalize for both type of objects using IDisposable Pattern.

Q27. Which gives a better performance – finalize or dispose?

Dispose gives better performance.
Because Finalize used 2 step process for freeing the memory. 
Step 1, It creates a pool of object/class which have Destructor and does not have any references.
Step 2, Then it frees the resources and reclaims memory. 

Q28. What is IDisposable pattern? Why should we use it?

IDisposable pattern is used for combining Finalize and Dispose method implementation.

With this pattern, we can achieve efficient memory management. This pattern also allows finalize() to clean unmanaged resources. It also provides a safety net in case if the user forgets to call Dispose method, as it will be cleaned when destructor will be invoked.

// Code
public static MyClass : IDisposable
    Private bool statusDisposed = false;    
    // IDisposable interface’s method implementation
    Public void Dispose()
    Protected virtual void Dispose(bool isdisposing)
     if(!statusDisposed )
                // TODO : Clean up managed objects.
            // TODO : Clean up unmanaged objects.
            statusDisposed = true;
  ~ MyClass()

Q29. What is Reflection? Why do we use reflection?

Updating soon…

Q30. What is Generics? What is the advantage of using Generics?


Generic is a feature of C# which enables the class, methods, property to work with any type. For example, List is a generic collection, so we can create a list of any type such as int, string etc.

The need for using generic is to eliminate the process of boxing and unboxing.

For example, ArrayList is a non-generic collection, it can store any data type value.

While storing items into the ArrayList, each item (whether it is value type or reference type) is converted to Object type and when retrieving, item needs to convert back to their respective type.

here, boxing and unboxing, gives a performance hit as it needed to allocate and deallocate memory for several temp variable.

So, using generic, we can use one type at one time. For example, List<int> will contain only int value. List<string> will contains the only string. here, We don’t need any boxing and unboxing involved.



This was the first post in this series of interview questions. In the next upcoming post, interview questions on other topics will be added such as C#, object-oriented, data structure, SQL server, web API.

Feel free to comment and any questions on these topics. I would love to clarify and updated in the upcoming interview questions article here. Best of luck.


Software professional, Blogger, Tech enthusiast.