.NET Interview Questions

Here is a list of Top 50 .NET interview questions and answers.

Question 1. What is .NET

.NET is a software development framework for building Desktop, Web, Mobile, Cloud, and Gaming software applications. .NET was introduced by Microsoft in 2002.

Currently, .NET has two versions, .NET Framework, and .NET Core. While .NET Framework is the original .NET, the .NET Core is the new .NET. Going forward, there is going to be only one version of .NET and it will be called “.NET”. The next version of .NET will be .NET 5 that is expected to be released in 2020.

Question 2. What is .NET 5

.NET Core is the future of .NET. The current version of .NET Core is .NET Core 3.0. Going forward, the “Core” will be dropped from the .NET and it will just be “.NET”. The next version of .NET Core 3.0 is .NET 5. .NET 5 is a unified platform that brings .NET everything under a single unified platform including major high-level libraries and APIs, low-level libraries, type systems, run-time components, compilers, languages, and tools.

.NET 5 provides libraries, frameworks, tools, and APIs to build, test, run, and deploy software that targets all platforms including Windows, Linux, IoTs, macOS, iOS, Android, tvOS, watchOS and WebAssembly, and all devices including desktops, web browsers, IoT devices, tablets, mobile phones, and more.

.NET 5 will be available to the public in 2020. Here is the complete coverage of where the .NET is heading in future.

Question 3. What are components of .NET

.NET Interview Questions

.NET is a unified platform for building software applications. .NET consists of runtime components, compilers, languages, libraries, tools, CLR, CTS, and other components.

Here is a list of .NET components.

  1. Runtime components
  2. Compilers
  3. Languages
  4. .NET Standard
  5. Tooling

.NET consists of runtime components, compilers, languages, libraries, tools, CLR, CTS, and other components. .NET supports several programming languages including C#, VB.NET, and F# and the language compilers are an essential part of .NET.

.NET Runtime is the engine that manages and runs .NET applications. Runtime includes execution engines for Mono (Xamarin), UWP, and other sub frameworks.

Languages including Common Type System (CTS) and Common Language Specification (CLS) that define the specifications of how types are defined and works is another major component of .NET.

.NET Standard is the center point of the .NET ecosystem. .NET Standard is a setup of APIs and libraries that is common to all .NET versions. .NET Standard,

  • Defines a uniform set of BCL APIs for all .NET implementations to implement, independent of workload.
  • Enables developers to produce portable libraries that are usable across .NET implementations, using this same set of APIs.
  • Reduces or even eliminates conditional compilation of shared source due to .NET APIs, only for OS APIs.

.NET provides a set of tools and IDEs to build, compile, debug, and run .NET applications. These tools include the .NET project system (based on .csproj, .vbproj, and .fsproj files), MSBuild, the build engine used to build projects, NuGet, Microsoft's package manager for .NET, and Open-source build orchestration tools, such as CAKE and FAKE.

Question 4. What is CLR

The heart of .NET Framework is a run-time environment called the common language runtime (CLR). The CLR manages the life cycle and executes .NET applications (code). It also provides services that make the development process easier. Benefits of .NET CLR

The runtime provides the following benefits:

  • Performance improvements.
  • The ability to easily use components developed in other languages.
  • Extensible types provided by a class library.
  • Language features such as inheritance, interfaces, and overloading for object-oriented programming.
  • Support for explicit free threading that allows the creation of multithreaded, scalable applications.
  • Support for structured exception handling.
  • Support for custom attributes.
  • Garbage collection.
  • Use of delegates instead of function pointers for increased type safety and security.

Question 5. What is CTS?

Languages including Common Type System (CTS) and Common Language Specification (CLS) that define the specifications of how types are defined and works is another major component of .NET.

CTS is a standard that specifies how types are declared, used and managed in the common language runtime and it is intended to allow programs written in different programming languages to easily share information. It establishes a framework that helps enable cross-language integration, enforces type security and defines rules which languages must follow to ensure that objects written in different languages can interact with each other.

Question 6. What is the difference between .NET Core and .NET Framework

.NET Framework was announced by Microsoft in 2001. Today, there are two different versions of .NET, .NET Framework and .NET Core.

.NET Interview Questions

.NET Framework is used to develop today’s applications. .NET Core is the new open-source .NET. Going forward, there will just be one .NET, that is .NET Core.

Question 7. What is the future of .NET

Microsoft just announced .NET 5, the next version of its .NET Core. There will be no .NET Core in the future. It will just be .NET, and .NET 5 is the future of .NET, which is expected to be available on November 2020. .NET 5 is a single unified platform for building software for all platforms and all devices.

Currently, there are two versions of .NET -- .NET Framework and .NET Core. Going forward, there is going to be only one version of .NET and that is, .NET 5. .NET 5 takes the best of .NET Core, .NET Framework, Xamarin, and Mono to provide libraries, APIs, and run-time to build applications for Windows, Web, Mobile, and IoT devices.

C# 8.0 is the latest version of C# language that is supported in Visual Studio 2019. If you plan to build a new application in .NET, you should use .NET Core 3.0 (the current version) and C# 8, that will later be converted to a .NET 5 project. I’m assuming it will have no or minimal changes.

Question 8. What is C#

C#, developed by Microsoft and released in 2000 is a modern, simple, and powerful object-oriented programming language. C# s one of the most popular programming languages for Windows, Web, and mobile development. You can build C# Windows applications using WinForms, WPF, and UWP platforms. ASP.NET MVC and ASP.NET Core are two technologies used to build modern web applications. Mobile developers can use the C# language to build native iOS, Android, and Windows mobile apps using Xamarin and UWP platforms. TypeScript also adds a new dimension to Web and App development.

Question 9. Why C# is important in .NET Development

C# is the primary language of ,NET. C#, as a language, can do a lot more. Today, you can build pretty much any kind of software using C# including data science, AI and machine learning, cloud, enterprise, and report-centric applications, What Can C# Do For You

Question 10. What is the future of C#

C# 1.0 was announced in 2000 and it is still evolving. The current version of C# is 8.0, that is one of the most advanced, powerful, and flexible language. The future of C# is bright. Learn more here, What Is The Future Of C# 

Question 11. How to choose between ASP.NET and ASP.NET Core?

If you’re building a web application for .NET Framework, you will choose ASP.NET and if you’re targeting your Web application for .NET Core, you will use ASP.NET Core.

Learn more here, ASP.NET Or ASP.NET Core, What To Choose? 

Question 12. What is ASP.NET MVC

MVC (Model View Controller) is an architectural pattern. It separates the application into three main components. The three compounds are Model, View, and Controller. It handles specific development aspects of an application. MVC is the most frequently used industry-standard web development framework.

ASP.NET MVC is Microsoft’s Web development framework targets .NET.

Question 13. What are Boxing and Unboxing in .NET

Boxing and unboxing enable a unified view of the type system wherein a value of any type can ultimately be treated as an object. Converting a value type into a reference type is called Boxing. Unboxing is an explicit operation.

Question 14. What is Blazor

Blazor is a new .NET web framework for creating client-side applications using C#/Razor and HTML that runs in the browser with WebAssembly. It can simplify the process of creating a single page application (SPA) and at the same time enables full-stack web development using .NET.

Using .NET for developing Client-side application has multiple advantages that are mentioned below,

  1. .NET offers a range of API and tools across all platform that are stable and easy to use.
  2. The modern languages such as C# and F# offer a lot of features that make programming easier and interesting for developers.
  3. The availability of one of the best IDE in the form of Visual Studio provides a great .NET development experience across multiple platforms such as Windows, Linux, and macOS.
  4. .NET provides features such as speed, performance, security, scalability, and reliability in web development that makes full-stack development easier.

Question 15. What is the difference between string and String in .NET

In any programming language, to represent a value, we need a data type. The Char data type represents a character in .NET. In .NET, the text is stored as a sequential read-only collection of Char data types. There is no null-terminating character at the end of a C# string; therefore a C# string can contain any number of embedded null characters ('\0'). 

The System.String data type represents a string in .NET. A string class in C# is an object of type System.String. The String class in C# represents a string.

Question 16. What is String Interpolation?

String Interpolation is nothing but a way to concatenate two or more strings together. As we are aware of, in the previous version of .NET we did string concatenation using the + (plus) operator. Sometimes for the same work, we have also used the String.Format method. Now we are pleased to hear that it became the old way to do string concatenation.

Learn more here, String Interpolation In C# 

Question 17. What are Jagged Arrays in .NET

An Array in C# is a collection of objects or types. C# Array elements can be of any type, including an array type. An array can be Single-Dimensional, Multidimensional or Jagged. A C# Array can be declared as fixed-length or dynamic. An Array in C# can be a single dimension, multi-dimension, or a jagged array. Learn how to work with arrays in C#.

In C#, an array index starts at zero. That means the first item of an array starts at the 0thposition. The position of the last item on an array will the total number of items - 1. So if an array has 10 items, the last 10th item is at 9th position.

Jagged arrays are arrays of arrays. The elements of a jagged array are other arrays.

Declaration of a jagged array involves two brackets. For example, the following code snippet declares a jagged array that has three items of an array.

int[][] intJaggedArray = new int[3][];

The following code snippet declares a jagged array that has two items of an array.

string[][] stringJaggedArray = new string[2][];

Question 18. What is the difference between a Queue and a Stack in .NET

Queue and stack are two common implementations when creating linked lists. A queue uses the first-in-first-out algorithm. The stack uses a last-in-first-out algorithm. Both are generic collections in C# and .NET. In the code examples of this article, we will learn about and how to work with Queue and Stack collection classes of .NET in C#.

Question 19. What is the purpose of Generics in .NET

Generics in C# and .NET procedure many of the benefits of strongly-typed collections as well as provide a higher quality of and a performance boost for code. Generics are very similar to C++ templates but having a slight difference in such a way that the source code of C++ templates is required when a template is instantiated with a specific type and .NET Generics are not limited to classes only. In fact they can also be implemented with Interfaces, Delegates and Methods. The detailed specification for each collection is found under the System.Collection.Generic namespace.

Question 20. What is the difference between a DataSet and a DataReader? When should you choose one over the other?

A DataReader provides read-only (cannot update data back to a data source) and forward-only (cannot read backward/random) data from a database.

A DataSet is an in-memory representation of data and can be used to store, bind, and update data via data-bound controls.

Question 21. What is the difference between Thread.Sleep and Thread.Abort

The Thread.Sleep() method blocks the current thread for the specified number of milliseconds. In other words, we can say that it suspends the current thread for a specified time.

The Thread.Abort() method is used to start the process of terminating the thread. This method is called to terminates the thread. The method raises the System.Threading.ThreadingAbortException in the thread in which it is invoked.

Question 22. What is the use of Global Assembly Cache

If an assembly is to be accessed by multiple applications, the assembly must be placed into a well-known directory, and the CLR must know to look in this directory automatically when a reference to the assembly is detected. This well-known location is called the global assembly cache (GAC), which can usually be found in the following directory (assuming that Windows is installed in the C:\Windows directory): C:\Windows\Assembly

Question 23. What is the purpose of Garbage Collector in .NET. What is Garbage Collector?

When the application calls a new operator to create an object, there might not be enough space left in the managed heap to allocate the object. In case of insufficient space, CLR performs garbage collection, which works in the generations. CLR garbage collector is also known as Ephemeral Garbage Collector (Generation based GC).

A Garbage Collector is an automatic memory manager. Garbage collection is a process of releasing the memory used by the objects that are no longer referenced. It has the following advantages.

  • It allows us to develop an application without having to free memory.
  • It efficiently allocates an object on the managed heap.
  • It reclaims object memories that are no longer being used.
  • It provides memory safety by making sure that an object cannot use the content of another object.

For more details, visit Garbage Collection In Depth

Question 24. What is an assembly in .Net? Explain the different types of assembly.

The .NET assembly is the standard for components developed with the Microsoft.NET. Dot NET assemblies may or may not be executable, i.e., they might exist as the executable (.exe) file or dynamic link library (DLL) file. All the .NET assemblies contain the definition of types, versioning information for the type, meta-data, and manifest. The designers of .NET have worked a lot on the component (assembly) resolution.

.NET supports three kinds of assemblies:

  • Private
  • Shared
  • Satellite

Private Assembly

Private assembly requires us to copy separately in all application folders where we want to use that assembly’s functionalities; without copying, we cannot access the private assembly features and power. Private assembly means every time we have one, we exclusively copy into the BIN folder of each application folder.

Public Assembly

Public assembly is not required to copy separately into all application folders. Public assembly is also called Shared Assembly. Only one copy is required in system level, there is no need to copy the assembly into the application folder.

Public assembly should install in GAC.

Shared assemblies (also called strong named assemblies) are copied to a single location (usually the Global assembly cache). For all calling assemblies within the same application, the same copy of the shared assembly is used from its original location. Hence, shared assemblies are not copied in the private folders of each calling assembly. Each shared assembly has a four-part name including its face name, version, public key token, and culture information. The public key token and version information makes it almost impossible for two different assemblies with the same name or for two similar assemblies with a different version to mix with each other.

Satellite Assembly

Satellite assemblies are used for deploying language and culture-specific resources for an application.

Question 25. Dispose and Finalize in .NET

Garbage collector (GC) plays the main and important role in .NET for memory management so the programmer can focus on the application functionality. Garbage collector is responsible for releasing the memory (objects) that are not being used by the application. But GC has the limitation that, it can reclaim or release only memory which is used by managed resources. There are a couple of resources which GC is not able to release as it doesn't have information that, how to claim memory from those resources like File handlers, window handlers, network sockets, database connections, etc. If your application uses these resources, it is the program's responsibility to release unmanaged resources. For example, if we open a file in our program and not closed it after processing than that file will not be available for other operation or it is being used by other application than they can not open or modify that file. For this purpose, the FileStream class provides the Dispose method. We must call this method after file processing finished. Otherwise, it will through exception Access Denied or file is being used by another program.

Question 26. What is CLS?

CLS is a subset of CTS, it specifies a set of rules that needs to be satisfied by all language compilers targeting CLR. CLS are mere guidelines and restrictions that a language should follow so that they can communicate with other .NET languages in a smooth manner.

Question 26. What is JIT?

  1. The JIT compiler translates the MSIL code of an assembly to native code and uses the CPU architecture of the target machine to execute a .NET application.
  2. It also stores the resulting native code so that it is accessible for subsequent calls.
  3. If a code executing on a target machine calls a non-native method, the JIT compiler converts the MSIL of that method into native code.
  4. The JIT compiler also enforces type-safety in the runtime environment of the .NET Framework.
  5. It checks for the values that are passed to parameters of any method.

Question 27. How JIT Works?

Before MSIL(MS Intermediate Language) can be executed, it must be converted by .net Framework Just in time (JIT) compiler to native code, which is CPU-specific code that run on some computer architecture as the JIT compiler. Rather than using time and memory to convert all the MSIL in portable executable (PE) file to native code, it converts the MSIL as it is needed during execution and stored in resulting native code so it is accessible for subsequent calls.

Question 28. What are the types of JIT?

  • Pre - JIT.
  • Econo - JIT.
  • Normal - JIT.

Pre - JIT

  1. In Pre-JIT compilation, complete source code is converted into native code in a single cycle (i.e. compiles the entire code into native code in one stretch)
  2. This is done at the time of application deployment.
  3. In .Net it is called "Ngen.exe"

Econo - JIT

  1. In Econo-JIT compilation, the compiler compiles only those methods that are called at run time.
  2. After the execution of this method, the compiled methods are removed from memory.

Normal - JIT

  1. In Normal-JIT compilation, the compiler compiles only those methods that are called at run time.
  2. After executing this method, compiled methods are stored in a memory cache.
  3. No further calls to compiled methods will execute the methods from the memory cache.

Question 29. What is the difference between managed and unmanaged code

Managed Code

In simple terms the code which is executed by CLR (Common Language Runtime) is called Managed Code, any application which is developed in .Net framework is going to work under CLR, the CLR internally uses the Garbage Collector to clear the unused memory and also used the other functionalities like CTS, CAS etc.

If we need to execute the Managed code application we must need to install .Net frame work as we need CLR to execute this code.

Unmanaged Code

The unmanaged code is basically developed using other languages (other than .Net Framework), so it uses its own language runtime to execute the applications. The application runtime will take care of its memory management, security etc...

Even if we do not install .Net framework the unmanaged code will work properly as it is not depending on the CLR.

We can also run unmanaged code using managed code by using commands, but even if we run the unmanaged application using .Net code the CLR is not having control to run that application, the application uses its own runtime to execute.

Question 30. What is the difference between value type and reference type

Reference Types: 

  • Always allocated from the managed heap.
  • Always represented in boxed form.
  • When we assign a value type to another value type, a field-by-field copy is made.

Value Types: 

  • Allocated on thread's stack
  • Have two form representations "boxed" and "unboxed"
  • When we copy a reference type to another reference type, only the memory address is copied.

Ref Vs Out

Ref Out
The parameter or argument must be initialized first before it is passed to ref. It is not compulsory to initialize a parameter or argument before it is passed to an out.
It is not required to assign or initialize the value of a parameter (which is passed by ref) before returning to the calling method. A called method is required to assign or initialise a value of a parameter (which is passed to an out) before returning to the calling method.
Passing a parameter value by Ref is useful when the called method is also needed to modify the pass parameter. Declaring a parameter to an out method is useful when multiple values need to be returned from a function or method.
It is not compulsory to initialize a parameter value before using it in a calling method. A parameter value must be initialized within the calling method before its use.
When we use REF, data can be passed bi-directionally. When we use OUT data is passed only in a unidirectional way (from the called method to the caller method).
Both ref and out are treated differently at run time and they are treated the same at compile time.
Properties are not variables, therefore it cannot be passed as an out or ref parameter.

For more details visit C# Concepts - Value Type And Reference Type

Question 31. What is Microsoft Intermediate Language(MSIL)

(MSIL) is a language used as the output of a number of compilers (C#, VB, .NET, and so forth).

The ILAsm program (Intermediate Language Assembler) generates an executable file from the MSIL language. We can find this program in the WINNT\Microsoft.NET\Framework\vn.nn.nn directory.

All operations in MSIL are executed on the stack. When a function is called, its parameters and local variables are allocated on the stack. Function code starting from this stack state may push some values onto the stack, make operations with these values, and pop values from the stack.

Execution of both MSIL commands and functions is done in three steps:

  1. Push command operands or function parameters onto the stack.
  2. Execute the MSIL command or call function. The command or function pops their operands (parameters) from the stack and pushes onto the stack result (return value).
  3. Read result from the stack.

Question 32. Explain page life cycle and order of events

When an ASP.NET page runs, the page goes through a life cycle in which it performs a series of processing steps. These include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. The following are the various stages or events of ASP.Net page life cycle.

  • PreInit 
  • Init
  • InitComplete
  • OnPreLoad
  • Load
  • Control PostBack Event(s)
  • LoadComplete
  • OnPreRender
  • OnSaveStateComplete
  • Render Method
  • UnLoad

For more details, visit Page Life Cycle In ASP.NET

Question 33. What is caching?

A cache is the most valuable feature that Microsoft provides. It is a type of memory that is relatively small but can be accessed very quickly. It essentially stores information that is likely to be used again. For example, web browsers typically use a cache to make web pages load faster by storing a copy of the webpage files locally, such as on your local computer.

Caching

Caching is the process of storing data into cache. Caching with the C# language is very easy. System.Runtime.Caching.dll provides the feature for working with caching in C#.

For more details, visit Working With Caching in C#

Question 34. What is a delegate in .NET?

Delegate is one of the base types in .NET. Delegate is a class, which is used to create and invoke delegates at runtime.

C# Delegates

A delegate in C# is similar to a function pointer in C or C++. It's a new type of object in C#. Delegate is very special type of object as earlier the entire the object we used to defined contained data but delegate just contains the details of a method.

For more details, visit C# .NET Delegates and Events

Question 35. What is MIME in .NET?

MIME stands for "Multipurpose Internet Mail Extensions." It is a standard way of classifying file types on the Internet. By specifying a MIME type, application can easily identify the type of file and can extract more information and attributes about a file.

Question 36. Explain localization and globalization.

Globalization is the process of designing the application in such a way that it can be used by users from across the globe (multiple cultures).

Localization, on the other hand, is the process of customization to make our application behave as per the current culture and locale. These two things go together.

For more details, visit What is Globalization and Localization in ASP.Net

Question 37. What is the difference between IEnumerable and ICollection?

IEnumerable interface has only single method - GetEnumerator() and it must return an instance of an object of a class which implements the IEnumerator interface.

ICollection inherits IEnumerable apart from it contains some more method and IsSynchronized and SyncRoot properties help to make the collection thread-safe. ICollection supports count property too.

Question 38. What are Minimal APIs In .NET 6?

Minimal API is a new template that uses all the C# 10 features and .NET 6 to create simple services with less complexity, layers, classes or using the traditional MVC template with controllers. This is inspired by other technologies like node.js, python, and go.

For more details, visit Create A Minimal Web API With ASP.NET Core

Question 39. What is changed in Razor compiler in .net 6?

Razor compiler updated to use source generators. Razor compiler no longer produces a separate views assembly.

For more details, visit Getting Started With ASP.NET Core 6.0

Question 40. What is hot reload in .net?

Hot Reload is one of the coolest features added to .NET that allows developers to modify the source code while it is running and visualize these changes in real-time without the need to restart the application. Hot Reload works in both Visual Studio and CLI.

Question 41. Explain PriorityQueue Class In .NET 6

The usage of priority queue is to allow us to add elements with a priority number which will be used to dequeue based on priority number. Unlike a normal queue that uses the concept of first-in-first-out, it works based on the priority of a value assigned to a value. There are many use cases when priority is a primary requirement.It is available as part of the namespace “System.Collections.Generic” as it is part of the generic collection. The class name is “PriorityQueue”. Generic Type is “PriorityQueue<TElement, TPriority>”.

For more details, visit New Generic Collection In .NET 6 - A Priority Queue

Question 42. What Is New In .NET 6.0?

.NET 6 is the latest version of .NET that was released in Nov 2021. Not only is .NET 6 a much improved version of the framework compared to its predecessors, but it also introduces some of the coolest features we’ve seen in some of the most popular platforms and languages. This article talks about the latest updates and new features introduced in in .NET 6.0.

For more details, visit What Is New In .NET 6.0?

What is Bufferless reads in ASP.NET Core 6?
IAsyncDisposable in .Net 6?

What is ahead-of-time (AOT) compilation?
 

More Interview Questions

Most of the .NET Interview Questions include questions related to C# language, ADO.NET, and other .NET libraries. Here are further recommended readings,


Recommended Ebook

Diving Into Microsoft .NET Entity Framework

Download Now!
Similar Articles