List of Most Frequently Asked .Net Interview Questions And Answers to Help You Prepare For The Upcoming Interview:
.Net is the most widely used framework for developing applications on windows. It encompasses ASP .Net, languages such as C#, VB .Net, Cobol, Perl, etc.
It is not possible to cover all the vast concepts of .Net in one article. Hence, the following section only consists of questions related to the .Net framework and its core. For more questions on .Net C#, please refer to C# interview questions.
This article will enlist the top 20 most popular .Net interview questions and answers in simple terms along with examples for your easy understanding.
Most Popular .Net Interview Questions
Here we go!!
Q #1) What is the .Net framework?
Answer: It is a platform for building various applications on windows. It has a list of inbuilt functionalities in the form of class, library, and APIs which are used to build, deploy and run web services and different applications. It supports different languages such as C#, VB .Net, Cobol, Perl, etc.
This framework supports the object-oriented programming model.
Q #2) What are the important components of .Net?
Answer: The components of .Net are Common language run-time, .Net Class library, Application domain, Common Type System, .Net framework, Profiling, etc. However, the two important components are the Class library and the Common Language Runtime.
CLR provides building blocks for a wide variety of applications. The class library consists of a set of classes that are used to access common functionality. The functionality can be shared among different applications.
Q #3) What is CTS?
Answer: CTS stands for Common Type System. It has a set of rules which state how a data type should be declared, defined and used in the program. It describes the data types that are to be used in the application.
We can design our own classes and values by following the rules that are present in the CTS. The rules are made so that the data type declared using a programming language can be called by an application that is developed using a different language.
Q #4) What is CLR?
Answer: CLR stands for Common Language Runtime. It is one of the most important components of the .Net framework. It provides building blocks for many applications.
An application built using C# gets compiled by its own compiler and is converted into an Intermediate language. This is then targeted to CLR. CLR does various operations like memory management, security checks, assemblies to be loaded and thread management. It provides a secure execution environment for applications.
Q #5) What is CLS?
Answer: CLS stands for Common Language Specification. With the rules mentioned under CLS, the developers are made to use the components that are inter-language compatible. They are reusable across all the .Net Compliant languages.
Q #6) What is JIT?
Answer: JIT stands for Just In Time. JIT is a compiler that converts Intermediate Language to a Native code.
The code is converted into Native language during execution. Native code is nothing but hardware specifications that can be read by the CPU. The native code can be stored so that it is accessible for subsequent calls.
Q #7) What is MSIL?
Answer: MSIL stands for Microsoft Intermediate Language.
MSIL provides instructions for calling methods, initializing and storing values, operations such as memory handling, exception handling and so on. All .Net codes are first compiled to IL.
Q #8) What is meant by Managed and Unmanaged code?
Answer: The code that is managed by the CLR is called Managed code. This code runs inside the CLR. Hence, it is necessary to install the .Net framework in order to execute the managed code. CLR manages the memory through garbage collection and also uses the other features like CAS and CTS for efficient management of the code.
Unmanaged code is any code that does not depend on CLR for execution. It means it is developed by any other language independent of .Net framework. It uses its own runtime environment for compiling and execution.
Though it is not running inside the CLR, the unmanaged code will work properly if all the other parameters are correctly followed.
Q #9) How is a Managed code executed?
Answer: Follow these steps while executing a Managed code:
- Choosing a language compiler depending on the language in which the code is written.
- Converting the above code into Intermediate language by its own compiler.
- The IL is then targeted to CLR which converts the code into native code with the help of JIT.
- Execution of Native code.
Q #10) What is ASP.Net?
Answer: ASP .Net is a part of .Net technology and it comprises of CLR too. It is an open-source server-side technology that enables the programmers to build powerful web services, websites and web applications.
ASP stands for Active Server Pages.
Q #11) Explain State management in ASP .Net.
Answer: 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, Client Side, and Server side.
- Client-Side – Storing the information in the Page or Client’s System. They are reusable, simple objects.
- Server Side – Storing the information on the Server. It is easier to maintain the information on the Server rather than depending on the client for preserving the state.
Q #12) What is an Assembly? What are the different types of Assemblies?
Answer: An Assembly is a collection of logical units. Logical units refer to the types and resources which are required to build an application and deploy them using the .Net framework. The CLR uses this information for type implementations. Basically, Assembly is a collection of Exe and DLLs. It is portable and executable.
There are two types of Assemblies, Private and Shared.
- Private Assembly, as the name itself suggests, it is accessible only to the application. It is installed in the installation directory of the application.
- Shared Assembly can be shared by multiple applications. It is installed in the GAC.
Q #13) Explain the different parts of an Assembly.
Answer: The different parts of an Assembly includes:
- Manifest – It contains the information about the version of an assembly. It is also called as assembly metadata.
- Type Metadata – Binary information of the program.
- MSIL – Microsoft Intermediate Language code.
- Resources – List of related files.
Q #14) What is an EXE and a DLL?
Answer: Exe and DLLs are Assembly executable modules.
Exe is an executable file. This runs the application for which it is designed. An Exe is generated when we build an application. Hence, the assemblies are loaded directly when we run an Exe. However, an Exe cannot be shared with the other applications.
DLL stands for Dynamic Link Library. It is a library that consists of code that needs to be hidden. 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 #15) What is Caching?
Answer: Caching means storing data temporarily in the memory so that the application can access the data from the cache instead of looking for its original location. This increases the performance of the application and its speed. System.Runtime.Caching namespace is used for Caching information in .Net.
Given below are the 3 different types of Caching:
- Page Caching
- Data Caching
- Fragment Caching
Q #16) What is MVC?
Answer: MVC stands for Model View Controller. It is an architectural model for building the .Net applications.
Models – 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 gets the information from the model objects for their display. They have components like buttons, drop boxes, combo box, etc.
Controllers – 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 #17) What is the difference between Function and Stored procedure?
- A Stored Procedure is always used to perform a specific task.
- It can return zero, one or more value.
- It can have both input and output parameters.
- Exception handling can be done using a try-catch block.
- A function can be called from a Procedure.
- Functions must return a single value.
- It can only have the input parameter.
- Exception handling cannot be done using a try-catch block.
- A Stored procedure cannot be called from a function.
Q #18) Explain CAS (Code Access Security).
Answer: .Net provides a security model that prevents unauthorized access to resources. CAS is a part of that security model. CAS is present in the CLR. It enables the users to set permissions at a granular level for the code.
CLR then executes the code depending on the available permissions. CAS can be applied only to the managed code. Unmanaged code runs without CAS. 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.
The different components of CAS are Code group, Permissions, and Evidence.
- Evidence– To decide and assign permissions, the CAS and CLR depend on the specified evidence by the assembly. The examination of the assembly provides details about the different pieces of evidence. Some common evidence include Zone, URL, Site, Hash Value, Publisher and Application directory.
- Code Group – Depending on the evidence, codes are put into different groups. Each group has specific conditions attached to it. Any assembly that matches those condition is put into that group.
- Permissions – Each code group can perform only specific actions. They 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 #19) 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 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 #20) What is meant by Globalization and Localization?
Answer: Internationalization is the process of designing applications that support multiple languages. This is divided into Localization and Globalization.
Globalization is nothing but developing applications to support different languages. Existing applications can also be converted to support multiple cultures.
Whereas Localization means changing the already globalized app 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 #21) What is a Garbage Collector?
Answer: Garbage collection is a .Net feature to free the unused code objects in the memory.
The memory heap is divided into three generations. Generation 0, Generation 1 and Generation 2.
- Generation 0 – This is used to store short-lived objects. Garbage Collection happens frequently in this Generation.
- Generation 1 – This is for medium-lived objects. Usually, the objects that get moved from generation 0 are stored in this.
- Generation 2 – This is for long-lived objects.
Collecting a Generation refers to collecting the objects in that generation and all its younger generations. Garbage collection of Generation 2 means full garbage collection, it collects all the objects in Generation 2 as well as Generation 1 and Generation 0.
During the Garbage collection process, as the first phase, the list of live objects is identified. In the second phase, references are updated for those objects which will be compacted. And in the last phase, the space occupied by dead objects are reclaimed. The remaining objects are moved to an older segment.
Recommended read => Popular ADO.Net Interview Questions
As we all know .Net is very vast and it is not possible to cover all the topics at a stretch.
Mostly, the interview questions will be in a specific language like C#. This article mainly concentrates only on the framework concepts of .Net. I’m sure that it would provide sufficient information and a fair knowledge of the common questions that will be asked during an interview.
STH team wishes you all success!!!