.Net Framework is the most widely used framework for developing the applications on windows. It supports multiple languages such as C#, VB .Net, C++, Perl, etc. to develop applications. The following section consists of top 20 interview questions with answers related to .Net framework.
Most Popular .Net Interview Questions and Answers
Given below is the list of most popular .Net interview questions and answers.
Question #1: What is the .NET Framework?
The .NET Framework is a run-time execution environment that primarily runs on windows and manages apps that target the .NET Framework.
It consists of two major components: the common language run-time (CLR), which is the execution engine that handles running apps. and the .NET Framework Class Library, which provides a library of tested, reusable code that developers can call from their own apps. It supports different languages such as C#, VB .Net, C++, Perl, etc.
Question #2: What is CLR(Common Language Runtime)?
CLR stands for Common Language Runtime and is an execution engine. It works as a layer between Operating Systems and the applications written in .NET languages.
The Common Language Runtime (CLR) manages the execution of .NET programs. A process known as just-in-time compiler converts compiled code into machine instructions which the computer’s CPU then executes.
The CLR provides additional services including memory management, type safety, exception handling, garbage collection, security and thread management. All programs written for the .NET framework, regardless of programming language, are executed by the CLR.
Question #3: What is CTS (Common Type System) ?
The Common Type System (CTS) standardizes the data types of all programming languages under the umbrella of .NET to a common data type for easy and smooth communication among these .NET languages.
For example: C# has int Data Type and VB.Net has Integer Data Type.
when we declare an int type data type in C# and VB.NET, then they are converted to System.Int32. Hence a variable declared as int in C# or Integer in VB.NET, finally after compilation, uses the same structure Int32 from CTS. The purpose of these is to support language independence in .NET. Hence it is called CTS.
Question #4: What is CLS (Common Language Specification) ?
One of the important goals of .NET Framework is to allow maximum compatibility across multiple languages. This
is achieved by CLS. For multiple languages to interoperate, it is necessary that they should go on in common in certain features such as Types that are used. For example, every language has its own size and range for different data types. Thus CLS is the agreement among language designers and class library designers concerning these usage conventions.
Question #5: What is MSIL (Microsoft Intermediate Language)?
When we compile our .NET application code then it is not directly converted to machine understandable code(native code), it is first converted into an intermediate code known as MSIL code which is then interpreted by the CLR with the help of JIT (Just-in-time compiler). MSIL is independent of hardware and the operating system. Cross language interactions are possible since MSIL is the same for all .NET languages.
Question #6: What is JIT ?
A process known as just-in-time compiler within the CLR converts compiled code(MSIL) into machine code instructions which the computer’s CPU then executes.
Question #7: What are different types of JIT?
JIT compiler is a part of the runtime execution environment. In Microsoft .NET there are three types of JIT compilers:
- Pre-JIT : 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 : Econo-JIT compiles only those methods that are called at runtime. However, these compiled methods are removed when they are not required.
- Normal-JIT : 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.
Question #8: What is meant by Managed and Unmanaged code ?
Code that targets the common language runtime, the foundation of the .NET Framework, is known as managed code.
You can think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety in the code. The concept of code management is a fundamental principle of the runtime.
Code that does not target the common language runtime is known as unmanaged code.
Question #9: What is portable executable (PE)?
Every .NET program first compiles with an appropriate compiler to MSIL packed into an assembly with extension of .exe or .dll depending upon the type of application.
The Portable Executable (PE) file format is used by Windows executables, object code, and DLLs. The PE file format is a data structure that contains the information necessary for the Windows OS loader to manage the wrapped executable code. Nearly every file with executable code that is loaded by Windows is in the PE file format, though some legacy file formats do appear on rare occasion in malware.
PE files begin with a header that includes information about the code, the type of application, required library functions, and space requirements.
Question #10: What is an application domain?
To ensure application and operating system security and stability, it is necessary to isolate concurrently executing applications from each other. Application isolation ensures that one application cannot purposefully or inadvertently modify the memory, or access the resources owned by another.
Traditionally, operating systems isolate applications by running each application in its own process, and providing each process with its own virtual memory space and resource handles. Memory references are associated with a single process, and therefore code cannot obtain a reference that affects the memory of another process.
The code that is type-safe(Type safety guarantees that the code does not perform illegal operations, access memory directly) allows the CLR to load many assemblies into the same operating system process without the risk of those assemblies crashing or corrupting each other.
An Application domains are logical containers within the CLR that provide an isolation boundary between type-safe assemblies equivalent to that provided by processes for native applications. It is a light-weight process having its own set of code, data, and configuration settings. Application domains are created by the runtime hosts, which are invoked by the common language runtime (CLR) to load the applications that need to be executed.
The relationship between a process, the CLR, application domains, and assemblies is shown below:
Question #11: What is an assembly?
An Assembly is a basic building block of .NET Framework applications. An assembly is a file that is automatically generated by the compiler upon successful compilation of every .NET application. It can be either a Dynamic Link Library or an executable file depending upon the project type.
An Assembly contains Intermediate Language (IL) code, Information about the types, Resource files and Assemblies manifest (name, language and version).
Question #12: What are the different types of assembly?
In .Net 3 types of Assemblies are available:
- Private Assemblies : Private Assemblies are designed to be used by one application and must reside in that application’s directory or subdirectory.
- Shared or Strong named assembly : Microsoft offers the shared assembly for those components that must be distributed. It centered around two principles. Firstly, called side-by-side execution, allows the CLR to house multiple versions of the same component on a single machine. Secondly, termed binding, ensures that clients obtain the version of the component they expect.
- Satellite Assembly : A satellite Assembly is defined as an assembly with resources only, no executable code.
Question #13: What is GAC?
The Global Assembly Cache (GAC) is a folder in Windows directory to store the .NET assemblies that are specifically designated to be shared by all applications executed on a system.
The concept of GAC addresses the issue of “DLL hell”(a common term for various problems associated with the use of DLL files.). The GAC is also the first in the search path while loading a .NET assembly. The only requirement for an assembly to be deployed in GAC is that it should have strong name. The CLR (Common Language Runtime) refers an assembly based on specific version mentioned by the calling application.
Question #14: What is a garbage collector?
A garbage collector(GC) is a piece of software that performs automatic memory management. Its job is to free any unused memory and ensure that no memory is freed while it is still in use. Some languages such as Java and .NET languages feature automatic garbage collection, whereas others such as C/C++ require the programmer to manual manage memory.
Question #15: What is code access security (CAS)?
Code access security (CAS) is part of the .NET security model that prevents unauthorized access of resources
and operations, and restricts the code to perform particular tasks.
If you have any query then please comment below and let us know. If you liked this article, then please follow us on Facebook to get notification for new posts.
Rakesh is a programming Geek, technology enthusiast, a passionate writer, thinker with passion for computer programming. He loves to explore technology and finds ultimate joy when writing about trending technology, geek stuff and web development.