.NET Interview Questions

Here is a list of top .NET Interview Questions. The article also explains the .NET interview question and answers. What is .NET? What are the advantages of .NET? What are the components of .NET framework? What are CLS and CTS?

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.
Learn more about what .NET Standard is and how to get started with .NET Standard 2.0.
 
.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.
What is Common Language Runtime (CLR)
 

Question 5. What are CTS and CLS?

 
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.
 
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 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.
 
Learn more here,

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.

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,

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,

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.
 
Learn more here,

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.
 
Learn more here,

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. 
Get started with Blazor here,

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.
 
Here is a complete tutorial on Strings in C#.
 

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,

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][];
 
Here is a detailed tutorial on Arrays in .NET,

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#.
 
Here is a detailed tutorial,

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.
 
Learn more about Generics in C# and .NET here,

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.
 
Learn more here,

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
 
Learn more here,

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

 
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).
 
Learn more details here,

Question 24. What are assemblies in .NET

 
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.
 
There is two kinds of assemblies in .NET, private and shared.
 
Learn more here,

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.
 
Learn more here,

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,