List of Top 30 .Net Interview Questions And Answers to brush up your knowledge before the interview:
.NET is the most widely used framework developed by Microsoft for developing applications that primarily runs on windows, which can be used for building applications that use .NET technologies such as desktop and web applications.
In this article we have covered top 30 most popular .Net interview questions and answers in simple language along with some examples for ease of understanding.
The Most asked .NET Interview Questions
Q-1) What is the .NET framework?
Answer: It is a framework for building different applications on windows which supports object-oriented approach. It has a wide list of inbuilt functionalities in the form of class, library, and APIs which are used to build, deploy and run web services and various applications. It supports various languages like C#, VB, Perl, .NET, Cobol, etc.
Q-2) What is CLR?
Answer: CLR stands for “Common Language Runtime”. It is one of the most important components of the .Net framework. We can use CLR as a building block of various applications. It is an execution engine for dot net applications. Whenever an C# application gets compiled, the code is converted into an intermediate language. After this then, the code is targeted to CLR which then performs various security checks at runtime to make sure that the code is safe to execute.
CLR also performs automatic memory management using Garbage Collector, and other operations like loading assemblies, and thread management.
Q-3) What are the different roles of CLR? **one of frequently asked .net interview questions
Following are the roles of CLR
- Convert Intermediate Language to Machine Level Language.
- Code Execution
- Code Management
- Memory Management
- Thread Management
- Exception Handling
- Garbage Collection
- Security Management.
Q-4) What is MSIL code?
Answer: MSIL stands for Microsoft Intermediate Language. MSIL code is platform neutral code. This code can be executed on any platform. MSIL code gets converted to native code for executing dot net applications.
Q-5) What are the different components of .NET?
Following are the components of .NET
- Common Language run-time
- Application Domain
- Common Type System
- .NET Class Library
- .NET Framework
Q-7) What is CTS?
Common Type System follows few rules according to which a data type should be declared and used in the program code. It also describes the data types that are going to be used in the application. By following the rules in the CTS we can make our own classes and functions.
CTS facilitates cross-language integration that means it helps in calling the data type declared in one program language by other programming languages.
Q-8) What is CLS?
Answer: CLS Stands for “Common language specification” and is a subset of CTS. It helps the developers to use the components that are inter-language compatible with certain rules that come with CLS. It then helps in reusing the code in other .NET compatible languages.
Q-9) Explain executions of .net applications in details.
Answer: CLR always executes managed code. Different types of applications created using .Net languages are executed on Dot Net platform. Source code written in a particular .Net language is first compiled by language specific compiler for example CSC compiler for C# and MSIL code is generated. It is a platform neutral code which is converted to native code.
Always first compilation is slow and second compilation fast. The native code is not stored permanently anywhere, after we close the program the native code is thrown away. When we execute the program again, the native code gets generated again.
Q-10) What is Assembly?
Answer: Assembly is the smallest unit of deployment of a .net application. It can be a dll or an exe. It is a functional building block of .Net applications.
Q-11) What are two types of Assembly? **one of frequently asked .net interview questions
- Private Assembly: A private assembly is normally used by a single application, and is stored in the application’s directory.
- Shared Assembly: A shared assembly is intended to be used by multiple applications, and is normally stored in the global assembly cache (GAC), which is a central repository for assemblies.
Q-12) What is GAC?
Answer: GAC stands for Global Assembly Cache. Whenever CLR gets installed on the machine, GAC comes as a part of it. GAC is central repository for assemblies and specifically stores those assemblies which will be shared by many applications.
A Developer tool called Gacutil.exe is used to add any file to GAC.
Q-13) What is Managed Code?
Answer: Managed Code is a code which is managed by CLR. By default every code written using any of the .net languages is a managed code. Language specific compilers convert this code into platform neutral non executable code called MSIL.
Q-14) What is Unmanaged Code?
Answer: Unmanaged code is a code which does not depend on CLR for execution and uses its own runtime environment for compiling and execution.
Unmanaged code is developed by any other language independent of .Net framework.
Though it is not running inside the CLR, the unmanaged code will work properly if all the other parameters are correctly followed.
Q-15) What is JIT and what is the use of it?
JIT means Just in Time compiler. It is a component of CLR. The term Just in Time means “take action as soon as request comes”. When a method is invoked the JIT compiler analyzes the MSIL code and produces highly efficient machine code. A small stub module is injected per method during the loading of the class. It contains the information whether the method is already compiled. JIT compiler checks this information and compiles only the code that is not yet converted to native code. As the .Net applications run, they tend to become faster and faster as the already-compiled code is reused.
Q-16) What are 3 types of JIT?
- Pre-JIT COMPILER: Pre-JIT compiles complete source code into native code in a single compilation cycle. This is done at the time of deployment of the application.
- Econo-JIT COMPILER: Econo-JIT compiles only those methods that are called at runtime. However, these compiled methods are removed when they are not required.
- Normal-JIT COMPILER: Normal-JIT compiles only those methods that are called at runtime. These methods are compiled the first time they are called, and then they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution. These methods are compiled the first time they are called, and then they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution.
Q -17) What is meant by Globalization and Localization?
Globalization is nothing but is the process of developing applications to support different languages. Existing applications can also be converted to support multiple languages/cultures.
Localization means changing the already globalized application to cater to a specific culture or language. Microsoft.Extensions.Localization is used for localizing the app content. Some of the other keywords that are used for Localization are IHtmlLocalizer, IStringLocalizer, IViewLocalizer and so on.
Q-18) What is the difference between Response.Redirect and Server.Transfer? **one of frequently asked .net interview questions
Response.Redirect redirects the user’s browser to another page or site. The history of the user’s browser gets updated to reflect the new address. It also performs a trip back to the client where the client’s browser is redirected to the new page.
Server.Transfer transfers from one page to the other without making any round-trip back to the client’s browser. The history of the user’s browser does not get updated in the case of Server.Transfer.
Q-19) What is the difference between constants and read-only variables? **one of frequently asked .net interview questions
Constants cannot be initialized at the time of declaration or in a constructor and evaluated at compile time. It support only value type variables and constants are used when the value is not changing at compile time.
Read-only Variables can be initialized at the time of declaration or in a constructor and evaluated at run-time. It supports reference type variables and read-only variables are used when the actual value is unknown before the run-time.
Q-20): Explain State management in ASP .Net. **one of frequently asked .net interview questions
State Management means maintaining the state of the object. The object here refers to a web page/control. There are two types of State management, Server side and Client Side
- Server Side – Information is stored on the Server. It is easier to maintain the information on the Server rather than depending on the client for preserving the state.
- Client-Side – Information is stored in the Page or Client’s System. They are reusable, simple objects.
Q-21) What is Caching?
Caching is nothing but the storing data temporarily in the memory so that the application can access the data from the memory instead of finding for its original location. This increases the performance of the application and its speed.
System.Runtime.Caching namespace is required for Caching information in .Net.
There are the 3 different types of Caching:
- Page Caching
- Data Caching
- Fragment Caching
Q -22) What is CAS (Code Access Security)?
CAS Stands for Code Access Security. CAS is a part of that security model provided by .Net that prevents unauthorized access to the resources. It can be only used for managed code. CAS enables the users to set permissions for the code.
CLR executes the code depending on the available permissions. If CAS is used on assemblies, then the assembly is treated as partially trusted. Such assemblies must undergo checks every time when it tries to access a resource.
There are 3 component of CAS:
- Evidence–CAS and CLR depends on the specified evidence by the assembly to decide and assign permissions. The examination of the assembly provides details about the various pieces of evidence. Some common evidence includes URL, Site, Zone, Hash Value, Publisher and Application directory.
- Code Group – Codes can put into different groups depending on the evidence. Each group has specific conditions attached to it. Any assembly that matches that condition is put into that group.
- Permissions – Each code group can perform certain actions that are called Permissions. When CLR loads an assembly, it matches them to one of the code groups and identifies what actions those assemblies can do. Some of the Permissions include Full Trust, Everything, Nothing, Execution, Skip Verification, and the Internet.
Q-23) What is a Garbage Collector? **one of frequently asked .net interview questions
Answer: In .Net, CLR has a garbage collector that executes as a part of our program and responsible for reclaiming the memory of no longer used objects.
Garbage collection is basically a .Net feature to free the unused objects in the memory.
The memory heap is divided into below three generations
- Generation 0 – This is used to store short-lived objects. Newly created objects are added to this generation. Garbage Collection happens frequently in this Generation.
- Generation 1 – This is for medium-lived objects. Usually, if the objects from generation 0 cannot be claimed then it’s moved to this generation.
- Generation 2 – This is for long-lived objects. If the objects from generation 1 cannot be claimed then it’s moved to this generation.
Please check below diagram to get more idea on generations.
In Simple words, when an object is first created, it is put into generation 0. When the generation 0 is filled up, the garbage collector is invoked.
The objects that survive the garbage collection in the generation 0 are then promoted onto the next higher generation i.e. generation 1.
The objects that survive garbage collection in generation 1 are promoted onto the next and the highest generation i.e. generation 2.
Q-24) What is DLL?
DLL stands for Dynamic Link Library. It is a library that consists of hidden code. The code is encapsulated inside this library. An application can consist of many DLLs. These can be shared with the other applications as well.
Other applications which share this DLL need not worry about the code intricacies as long as it is able to call the function on this DLL.
Q-25) What is MVC? **one of frequently asked .net interview questions
MVC stands for Model View Controller. It is a design pattern for developing dynamic web applications. It is an architecture model to organize and arrange the code in a better way.
Model – Model objects store and retrieve data from the database for an application. They are usually the logical parts of an application that is implemented by the application’s data domain.
View – These are the components that display the view of the application in the form of UI. The View component is basically used for all the UI logic of the application. The view gets the information from the model objects for their display. They have components like buttons, drop boxes, combo box, etc.
Controller – Controllers act as an interface between Model and View components to process all the business logic and incoming requests.
They handle user interactions. They are responsible for responding to the user inputs, work with the model objects, and pick a view to be rendered to the user.
Q-26) What is the main difference between Function and Stored procedure? **one of frequently asked .net interview questions
- Functions must return a single value.
- It can only have the input parameter.
- Exception handling cannot be done using a try-catch block.
- Cannot call a stored procedure from a function.
- There is no restriction on return value i.e. It can return zero, one or even more value.
- Stored Procedure can have input as well as output parameters.
- Exception handling can be done using a try-catch block.
- A function can be called from a Stored Procedure.
- A Stored Procedure is always used to perform a specific task.
Q-27) Explain Boxing and Unboxing? **one of frequently asked .net interview questions
Boxing is the process in which a value type is converted into a reference type.
When you box a variable, you are creating a reference variable that points to a new copy on the heap. A reference variable is an object and therefore can use all the methods that every object inherits, such as, ToString().
Please check below example to get more idea.
int a = 50; // variable ‘a’ is a value type object o = a; // ‘a’ is boxed
Unboxing is the process in which a reference type is converted into a value type.
int a = 50; // variable ‘a’ is a value type object o = a; // ‘a’ is boxed int b =(int)o; // ‘o’ is unboxed
Q-28) What are the different types of constructors in C#?
Types of constructors in C#:
- Default Constructor
- Parameterized constructor
- Copy Constructor
- Static Constructor
- Private Constructor
Q-29) What is the difference between interface and abstract class in .NET? **one of frequently asked .net interview questions
- Interface can have only abstract methods.
- Supports multiple inheritance.
- The interface keyword is used to declare interface.
- We cannot declare a member field in an Interface.
- An interface cannot have the constructor declaration.
- Abstract class can have abstract and non-abstract methods.
- Doesn’t support multiple inheritance
- The abstract keyword is used to declare an abstract class.
- Can declare a member in an abstract class.
- An abstract class can have a constructor declaration.
Q-30) List the events in the page life cycle.
Below are the events in the page life cycle:
Q-31) What is delegate in .NET? **one of frequently asked .net interview questions
A delegate in .NET is basically similar to a function pointer in other languages like C or C++. A delegate allows the user to encapsulate the reference of a method in a delegate object. A delegate object can then be passed in a program, which will call the referenced method. We can even use a delegate method to create a custom event in a class.
Q-32) What is the difference between an assembly and a namespace in .NET?
An assembly is a logical unit of code that is compiled and packaged for deployment, while a namespace is a mechanism for organizing classes and other types in code. An assembly can contain multiple namespaces.
Q-33) What is the difference between a static class and a singleton pattern in .NET?
A static class is a class that cannot be instantiated, and all its members must be static. The singleton pattern is a design pattern that ensures only one instance of a class is created. The difference is that a static class cannot be instantiated at all, while a singleton pattern allows for one instance of a class to be instantiated.
Q-34) What is the difference between a synchronous and asynchronous method call in .NET?
A synchronous method call blocks the calling thread until the method returns, while an asynchronous method call does not block the calling thread and allows it to continue executing other tasks. Asynchronous method calls in .NET can be achieved using the async/await keywords or the Task Parallel Library (TPL).
Q-34) What is LINQ, and how does it work in .NET?
LINQ (Language-Integrated Query) is a set of language extensions in .NET that provides a consistent and type-safe way of querying data from different sources such as arrays, databases, and XML. It works by providing a set of standard query operators that can be used with any data source that implements the IEnumerable or IQueryable interfaces.
We have covered 30+ most frequently asked .net interview questions in this article and we hope that it would provide enough information and fair knowledge of the common .net interview questions that will be asked during an interview. Wish you a very all the best!!!