Top 50 .NET Interview Questions and Answers

22 feb. 2024
419 Views
39 min read  

Top 50 .NET Interview Questions and Answers: An Overview

.NET is an ever-evolving framework developed by Microsoft. This powerful open-source development platform has been driving the software industry for years. It supports services, websites, desktop applications, and many more on Windows. In this .NET tutorial, we have tried our best to provide you with some of the top .NET Interview Questions and Answers. We have segregated the questions into .NET interview questions for freshers, intermediate .NET Interview Questions, and .NET Interview Questions for experienced to make it easy to go through the questions.

Basic .NET Interview Questions for Freshers

1. Describe the components of .NET.

 components of .NET.

.NET consists of the following components:

  1. Common Language Runtime(CLR): It is an execution engine that runs the code and provides services that make the development process easier. The programs written for the .NET Framework are executed by the CLR regardless of programming language.
  2. Framework Class Library(FCL): It has pre-defined methods and properties to implement common and complex functions. It will also provide types for dates, strings, numbers, etc. This class library includes APIs for database connection, file reading and writing, drawing, etc.
  3. Base Class Library(BCL): (BCL) has a huge collection of libraries features and functions that help implement various programming languages such as C#, F#, Visual C++, etc., in the .NET Framework.
  4. Common Type System(CTS): It specifies a standard that will mention which type of data and value can be defined and managed in memory during runtime.
  5. Common Language Specification (CLS): CLS will support inter-operability or cross-language integration, which means it provides a common platform for interacting and sharing information.

2. Differentiate managed from unmanaged code

Managed CodeUnmanaged Code
It is managed by CLR.It is not managed by CLR.
.NET framework is a must for execution.Does not require a .NET framework for the execution.
Memory management is done through garbage collection.The runtime environment takes care of memory management.

3. How do you apply themes to ASP.NET applications?

Yes. By modifying the following code in the web.config file, we can apply themes to ASP.NET applications:


<configuration>
   <system.web>
       <pages theme="windows"/>
   </system.web>
</configuration>

4. What is BCL?

What is BCL
  • BCL is a base class library of classes, interfaces, and value types
  • It is the foundation of .NET framework applications, components, and controls
  • Encapsulates a huge number of common functions and makes them easily available for the developers
  • It provides functionality like threading, input/output, security, diagnostics, resources, globalization, etc.
  • Also serves the purpose of interaction between the user and the runtime
  • It also provides namespaces that are used very frequently. for eg: system, system.Activities, etc.

5. Explain the concept of Just-In-Time (JIT) compilation in .NET.

  • 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.
  • It also stores the resulting native code to be accessible for subsequent calls.
  • 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.
  • The JIT compiler also enforces type safety in the runtime environment of the .NET Framework.
  • It checks for the values that are passed to the parameters of any method.

6. What is an assembly?

An assembly is a file that is automatically generated by the compiler which consists of a collection of types and resources that are built to work together and form a logical unit of functionality. In other words, assembly is a compiled code and logical unit of code. Assemblies are implemented in the form of executable (.exe) or dynamic link library (.dll) files.

7. Describe MVC.

MVC stands for Model View Controller. It is an architecture to build .NET applications. The three main logical components of MVC are the model, the view, and the controller.

Describe MVC

  1. Model: They hold data and its related logic. It handles the object storage and retrieval from the databases for an application. For example: A Controller object will retrieve the employee information from the database.

    It manipulates employee data and sends it back to the database or uses it to render the same data.

  2. View: View handles the UI part of an application. They get the information from the models for their display. For example, any employee view will include many components like text boxes, dropdowns, etc.
  3. Controller: They handle the user interactions, figure out the responses for the user input, and also render the final output. For instance, the Employee controller will handle all the interactions and inputs from the Employee View and update the database using the Employee Model.

8. What is a delegate in .NET?

A delegate in .NET is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked. In addition, we could use delegates to create custom events within a class.


public delegate void ScholarHatDelegate();

class ScholarHatClass
{
    // custom event
    public event ScholarHatDelegate ScholarHatEvent;
}

ScholarHatClass ScholarHatObj = new ScholarHatClass()
ScholarHatObj.ScholarHatEvent += new ScholarHatDelegate();

9. What is MIME in .NET?

MIME stands for Multipurpose Internet Mail Extensions. It is the extension of the e-mail protocol which lets users use the protocol to exchange files over emails easily.

Servers insert the MIME header at the beginning of the web transmission to denote that it is an MIME transaction. Then the clients use this header to select an appropriate ‘player’ for the type of data that the header indicates. Some of these players are built into the web browser.

10. What are the types of JIT?

 types of JIT
  1. Pre - JIT
    • Here, complete source code is converted into native code in a single cycle (i.e. compiles the entire code into native code in one stretch)
    • This is done at the time of application deployment.
    • In .Net it is called "Ngen.exe"
  2. Econo - JIT
    • In Econo-JIT compilation, the compiler compiles only those methods that are called at run time.
    • After the execution of this method, the compiled methods are removed from memory.
  3. Normal - JIT
    • In Normal-JIT compilation, the compiler compiles only those methods that are called at run time.
    • After executing this method, compiled methods are stored in a memory cache.
    • No further calls to compiled methods will execute the methods from the memory cache.

11. What is a garbage collector?

A garbage collector frees the unused code objects in the memory. The memory heap is partitioned into 3 generations:

  1. Generation 0: It holds short-lived objects.
  2. Generation 1: It stores medium-lived objects.
  3. Generation 2: This is for long-lived objects.

Collection of garbage refers to checking for objects in the generations of the managed heap that are no longer being used by the application. It also performs the necessary operations to reclaim their memory. The garbage collector must perform a collection to free some memory space.

During the garbage collection process:

  • The list of live objects is recognized.
  • References are updated for the compacted objects.
  • The memory space occupied by dead objects is recollected. The remaining objects are moved to an older segment.

System.GC.Collect() method is used to perform garbage collection in .NET.

12. What is boxing and unboxing in .NET?

Boxing is the process of converting a value type into a reference type directly. It is implicit.

Unboxing is the process where the reference type is converted back into a value type. It is explicit.

Example


int x = 15;      // a value type
object o = j;     // boxing
int y = (int)o;   // unboxing

13. What is Caching?

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.

The following are the three different types of Caching:

  1. Page Caching
  2. Data Caching
  3. Fragment Caching

14. Why C# is important in .NET Development?

C# is the primary language of .NET C#, as a language, can do a lot more. C# benefits from the rich standard library provided by the .NET framework, which includes a wide range of built-in classes and APIs for common programming tasks such as file I/O, networking, data manipulation, cryptography, and XML processing.

15. What is the appSettings section in the web.config file?

We can use the appSettings block in the web.config file, if we want to set the user-defined values for the whole application.


<em>
   <configuration>
       <appSettings>
           <add key= "ConnectionString" value="server=local; pwd=password; database=default"  />
       </appSettings>
   </configuration>
</em>
    

16. What are the types of memories supported in the .NET framework?

Two types of memories are present in .NET. They are:

  1. Stack: Stack is a stored-value type that keeps track of each executing thread and its location. It is used for static memory allocation.
  2. Heap: Heap is a stored reference type that keeps track of more precise objects or data. It is used for dynamic memory allocation.

17. What is manifest in .NET Framework?

Manifest is used to store assembly metadata. It contains all the metadata which are necessary for the following things:

  • Version of assembly
  • Security identity
  • Scope of the assembly
  • To resolve references to resources and classes

18. Why do we use Response.Output.Write()?

Response.Output.Write() is used to get the formatted output.

19. What is the difference between string and String in .NET?

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.

20. Explain the different types of cookies available in ASP.NET.

The following are the two types of cookies in ASP.NET. They are:

  1. Session Cookie: It resides on the client machine for a single session and is valid until the user logs out.
  2. Persistent Cookie: It resides on the user's machine for a period specified for its expiry. It may be an hour, a day, a month, or never.

Intermediate .NET Interview Questions

1. State the differences between .NET Core and Mono

 .NET Core Vs Mono
.NET CoreMono
.Net Core is the subset of implementation for the .NET framework by Microsoft itself.Mono is the complete implementation of the .Net Framework for Linux, Android, and iOS by Xamarin.
.NET Core only permits you to build web applications and console applications.Mono permits you to build different application types available in .NET Framework, including mobile applications, GUI-enabled desktop apps, etc.
.NET Core does not have the built-in capability to be compiled into WebAssembly-compatible packages.Mono has the built-in capability to be compiled into WebAssembly-compatible packages.
.NET Core is never intended for gaming. You can only develop a text-based adventure or relatively basic browser-based game using .NET Core.Mono is intended for the development of Games. Games can be developed using the Unity gaming engine that supports Mono.

2. Explain the different parts of an Assembly.

different parts of an Assembly.

The different parts of an assembly are:

  1. Manifest: An assembly manifest consists of complete metadata required to specify version requirements and security identity of an assembly, and also the metadata required for defining the assembly scope and resolving references to classes and resources.

    The assembly manifest will be stored in either a standalone PE(Portable Executable) file that holds only assembly manifest information, or in a PE file (a .exe or .dll) with MSIL(Microsoft intermediate language) code.

  2. Type Metadata: Metadata will be automatically generated by the Compilers from the source files and the compiler will embed this metadata within target output files like .exe, .dll, or a .netmodule(in the case of multi-module assembly).
  3. MSIL: Microsoft Intermediate Language(MSIL) is a code that implements the types. It includes instructions to load, store, initialize, and call the methods on objects. Along with this, it also includes instructions for control flow, direct memory access, arithmetic and logical operations, exception handling, etc. This is generated by the compiler using one or more source code files.
  4. Resources: Resources can be a list of related files such as .bmp or .jpg files. These resources are static, which means they do not change during run time. Resources are not executable items.

3. Explain the 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.

 page life cycle of ASP.Net

The following are the various stages or events of the ASP.Net page life cycle.

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

4. What is the difference between IEnumerable and ICollection?

  1. IEnumerable interface has only a single method - GetEnumerator() and it must return an instance of an object of a class that implements the IEnumerator interface.
  2. ICollection inherits IEnumerable apart from it contains some more methods and IsSynchronized and SyncRoot properties help to make the collection thread-safe. ICollection supports count property too.

5. What are the requirements needed for connection pooling?

There are three main requirements needed for connection pooling:

  1. The presence of an identical connection string for both entities
  2. The existence of multiple processes with the same connection parameters
  3. The presence of similar security protocols and settings

6. What is the role of the Startup class in .NET Core?

The Startup class is a fundamental component of the .NET Core web application architecture. It is responsible for configuring the application and its dependencies.

When the application starts, the Startup class is executed, and it performs the following tasks:

  • Sets up the environment: The Startup class sets up the hosting environment for the application, such as development, staging, or production. It also loads the configuration settings for the application.
  • Configures services: The Startup class is responsible for configuring the services that the application needs to function correctly.

7. Write a program to find a number of characters in a string.


using System;
namespace LogicalProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the string : ");
            string message = Console.ReadLine();

            //Remove the empty spaces from the message
            message = message.Replace(" ", string.Empty);
            
            while (message.Length > 0)
            {
                Console.Write(message[0] + " : ");
                int count = 0;
                for (int j = 0; j < message.Length; j++)
                {
                    if (message[0] == message[j])
                    {
                        count++;
                    }
                }
                Console.WriteLine(count);
                message = message.Replace(message[0].ToString(), string.Empty);
            }

            Console.ReadKey();
        }
    }
}
    

Output

Enter the string : ScholarHat
S : 1
c : 1
h : 1
o : 1
l : 1
a : 2
r : 1
H : 1
t : 1

8. What are some of the security controls present in ASP.NET?

There are five security controls present in ASP.NET:

  1. <asp: PasswordRecovery>: Used to send an email to a user upon performing a password reset operation
  2. <asp: Login>: Gives the provisions of login controls with ID and password fields for users to login via credentials
  3. <asp: LoginName>: Used to display the name of the user who has logged into the system
  4. <asp: LoginStatus>: Used to denote the authentication flag of the user who has logged in
  5. <asp: LoginView>: Used to provide a variety of views based on themes upon user login

9. What is CoreCLR?

CoreCLR is the run-time execution engine provided by the .NET Core. It consists of a JIT compiler, garbage collector, low-level classes, and primitive data types. .NET Core is a modular implementation of .NET, and can be used as the base stack for large scenario types, ranging from console utilities to web applications in the cloud.

CoreCLR

10. Differentiate .NET Core vs .NET framework.

Features.NET Core.NET framework
CompatibilityIt works based on the principle of “build once, run anywhere”. It is cross-platform, so it is compatible with different operating systems such as Linux, Windows, and Mac OS.This framework is compatible with the Windows operating system only. Even though, it was developed for supporting software and applications on all operating systems.
InstallationSince it is cross-platform, it is packaged and installed independently of the OS.It is installed in the form of a single package for Windows OS.
Application ModelsIt does not support developing the desktop application and it focuses mainly on the Windows mobile, web, and Windows store.It is used for developing both desktop and web applications, along with this it also supports Windows Forms and WPF applications.
Performance and ScalabilityIt provides high performance and scalability.It is less effective compared to .Net Core in terms of performance as well as scalability of applications.
Support for Micro-Services and REST ServicesIt supports developing and implementing the micro-services and the user is required to create a REST API for its implementation.It does not support the microservices’ development and implementation, but it supports REST API services.
Packaging and ShippingIt is shipped as a collection of Nugget packages.All the libraries that belong to the .Net Framework are packaged and shipped all at once.
Android DevelopmentIt is compatible with open-source mobile app platforms like Xamarin, via .NET Standard Library. Developers can make use of tools of Xamarin for configuring the mobile application for particular mobile devices like Android, iOS, and Windows phones.It does not support the development of mobile applications.
CLI ToolsFor all supported platforms, it provides lightweight editors along with command-line tools..NET is heavy for CLI(Command Line Interface) and developers usually prefer to work on the lightweight CLI.
Deployment ModelThe updated version of the .NET Core gets initiated on one machine at a time, which means it gets updated in new folders/directories in the existing application without affecting it. Thus, we can say that .NET Core has a very good flexible deployment model.When the updated version is released, it is deployed only on the Internet Information Server at first.

11. What is an inversion of control (IoC)? How is it achieved in .NET?

Inversion of Control (IoC) is a design principle that promotes loose coupling and modularity by inverting the traditional flow of control in software systems. Instead of objects creating and managing their dependencies, IoC delegates the responsibility of creating and managing objects to a container or framework. In .NET, IoC is commonly achieved through frameworks like Dependency Injection (DI) containers, where dependencies are injected into objects by the container, enabling flexible configuration and easier testing.

12. Is ASP.NET different from ASP? If yes, explain how.

Yes, ASP.NET is different from ASP. The following are the main differences:

  • ASP.NET is developed by Microsoft to create dynamic web applications while ASP (Active Server Pages) is Microsoft's server-side technology used to create web pages.
  • ASP.NET is compiled while ASP is interpreted.
  • ASP uses the technology named ADO while ASP.NET uses ADO.NET.
  • ASP.NET is completely object-oriented while ASP is partially object-oriented.

13. Write a code to send an email from an ASP.NET application


mail message = new mail();
message.From = "abc@gmail.com";
message.To = "xyz@gmail.com";
message.Subject = "Hello";
message.Body = "ScholarHat";
 
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(message);
    

14. What are the differences between custom and user control?

Custom ControlUser Control
Derives from control Derives from UserControl
Dynamic Layout Static Layout
Defines a single-control Defines a set of con
It has full toolbox support Cannot be added to the toolbox
Loosely coupled control Tightly coupled control

15. What are tuples in .Net?

A tuple is a fixed-size collection of elements of either the same or different data types. The user must have to specify the size of a tuple at the time of declaration just like arrays.

Advanced .NET Interview Questions for Experienced

1. What are EXE and DLL?

EXE and DLL are assembly executable modules.

  1. EXE: It is an executable file that runs the application for which it is designed. When we build an application, an exe file is generated. Therefore the assemblies are loaded directly when we run an exe. But an exe file cannot be shared with other applications.
  2. DLL: It stands for dynamic link library that consists of code that needs to be hidden. The code is encapsulated in this library, an application can have many DLLs and can also be shared with other applications.

2. What is GAC?

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.

3. What is the purpose of Generics in .NET?

Generics in .NET provide a powerful way to create classes, structures, interfaces, methods, and delegates that work with any data type. They allow you to define type-safe data structures and algorithms without committing to a specific data type at compile time. Generics are commonly used to create type-safe collections for both reference and value types.

The .NET framework provides an extensive set of interfaces and classes in the System.Collections.Generic namespace for implementing generic collections.


using System;

// We use < > to specify Parameter type
public class GFG<T> {
	
	// private data members
	private T data;
	
	// using properties
	public T value
	{
		
		// using accessors
		get
		{
			return this.data;
		}
		set
		{
			this.data = value;
		}
	}
}

// Driver class
class Test {
	
	// Main method
	static void Main(string[] args)
	{
		
		// instance of string type
		GFG<string> name = new GFG<string>();
		name.value = "GeeksforGeeks";
		
		// instance of float type
		GFG<float> version = new GFG<float>();
		version.value = 5.0F;
		
		// display GeeksforGeeks
		Console.WriteLine(name.value); 
		
		// display 5
		Console.WriteLine(version.value); 
	}
}
    

Output

ScholarHat
5  

4. Explain Thread.Sleep in .NET

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.

One thread cannot call Thread.Sleep on another thread. Thread.Sleep is a static method that always causes the current thread to sleep.

Calling Thread.Sleep with a value of Timeout.Infinite causes a thread to sleep until it is interrupted by another thread that calls the Thread.Interrupt method on the sleeping thread, or until it is terminated by a call to its Thread.Abort method. The following example illustrates both methods of interrupting a sleeping thread.


using System;
using System.Threading;

public class Example
{
   public static void Main()
   {
      // Interrupt a sleeping thread.
      var sleepingThread = new Thread(Example.SleepIndefinitely);
      sleepingThread.Name = "Sleeping";
      sleepingThread.Start();
      Thread.Sleep(2000);
      sleepingThread.Interrupt();

      Thread.Sleep(1000);

      sleepingThread = new Thread(Example.SleepIndefinitely);
      sleepingThread.Name = "Sleeping2";
      sleepingThread.Start();
      Thread.Sleep(2000);
      sleepingThread.Abort();
   }

   private static void SleepIndefinitely()
   {
      Console.WriteLine("Thread '{0}' about to sleep indefinitely.",
                        Thread.CurrentThread.Name);
      try {
         Thread.Sleep(Timeout.Infinite);
      }
      catch (ThreadInterruptedException) {
         Console.WriteLine("Thread '{0}' awoken.",
                           Thread.CurrentThread.Name);
      }
      catch (ThreadAbortException) {
         Console.WriteLine("Thread '{0}' aborted.",
                           Thread.CurrentThread.Name);
      }
      finally
      {
         Console.WriteLine("Thread '{0}' executing finally block.",
                           Thread.CurrentThread.Name);
      }
      Console.WriteLine("Thread '{0} finishing normal execution.",
                        Thread.CurrentThread.Name);
      Console.WriteLine();
   }
}
    

Output

Thread 'Sleeping' about to sleep indefinitely.
Thread 'Sleeping' awoken.
Thread 'Sleeping' executing finally block.
Thread 'Sleeping finishing normal execution.

Thread 'Sleeping2' about to sleep indefinitely.
Thread 'Sleeping2' aborted.
Thread 'Sleeping2' executing finally block.

5. What is the difference between Function and Stored procedure?

Stored Procedure:

  • A Stored Procedure is always used to perform a specific task.
  • It can return zero, one or more values.
  • 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:

  • 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.

6. 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 applications has multiple advantages like:

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

Read more: What's New in Blazor with .NET 8: A Guide to Blazor 8 New Features

7. What is LINQ?

It is an acronym for Language integrated query which was introduced with Visual Studio 2008. LINQ is a set of features that extend query capabilities to the .NET framework language syntax that allows data manipulation irrespective of the data source. LINQ bridges the gap between the world of objects and the world of data.

8. Differentiate between ExecuteScalar and ExecuteNonQuery

ExecuteScalarExecuteNonQuery
Returns the output valueDoes not return any value
Used for fetching a single valueUsed to execute insert and update statements
Does not return the number of affected rowsReturns the number of affected rows

9. What is an HTTP Handler?

Every request into an ASP.NET application is handled by a specialized component called HTTP handler. It is the most important component for handling ASP.NET application requests.

It uses different handlers to serve different files. The handler for the web page creates the page and control objects, runs your code, and then renders the final HTML.

Following are the default HTTP handlers for ASP.NET:

  • Page Handler(.aspx): Handles web pages
  • User Control Handler(.ascx): It handles web user control pages
  • Web Service Handler(.asmx): Handles web service pages
  • Trace Handler(trace.axd): It handles trace functionality

10. What is cross-page posting?

Whenever we click on a submit button on a webpage, the data is stored on the same page. But if the data is stored on a different page and linked to the current one, then it is known as a cross-page posting. Cross-page posting is achieved by the POSTBACKURL property.

To get the values that are posted on the page to which the page has been posted, the FindControl method can be used.

11. What is a reflection in .NET? Give its practical applications.

Reflection in .NET allows for introspection of types, methods, properties, and other members at runtime. It provides the ability to examine and manipulate metadata, dynamically invoke methods, and create instances of types. This is done through the System.Reflection namespace.


Type type = typeof(string);
Console.WriteLine("FullName:" + type.FullName);
Console.WriteLine("Namespace:" + type.Namespace);
Console.WriteLine("Is Public:"+ type.IsPublic);

In the above code, we are using reflection to get information about the string type such as its full name, namespace, and whether it's public.

  • Dynamic Loading: Reflection enables you to load assemblies, types, and resources dynamically at runtime.
  • Object Creation and Invocation: Reflection allows you to create instances of types dynamically and invoke their methods, properties, and events at runtime.
  • Introspection and Metadata Inspection: Reflection provides APIs to inspect the metadata of types, such as fields, properties, methods, attributes, and interfaces. This information can be used for various purposes, including code generation, documentation generation, serialization, and data binding.
  • Serialization and Deserialization: Reflection is used extensively in serialization frameworks like JSON.NET and XML serialization to dynamically inspect and serialize/deserialize object graphs without requiring explicit type information.
  • Unit Testing and Mocking: Reflection enables frameworks like NUnit and Moq to dynamically discover and execute unit tests and create mock objects based on test attributes and method signatures at runtime.
  • Aspect-Oriented Programming (AOP): Reflection is used in AOP frameworks like PostSharp and Castle Windsor to apply cross-cutting concerns such as logging, caching, and exception handling dynamically to methods and classes at runtime.

12. How is the status of a DataReader checked in .NET?

The status of a DataReader can be checked easily by using a property called ‘IsClosed.’ It will tell you if the DataReader is closed or opened.

If it is closed, a true value is returned, and if the reader is open, it returns a false value.

13. Explain passport authentication.

During the passport authentication, it first checks the passport authentication cookie, if the cookie is not available the application redirects to the passport sign-on page. The passport service then authenticates the details of the user on the sign-on page and if they are valid, stores them on the client's machine and then redirects the user to the requested page.

14. What is the difference between an abstract class and an interface?

Abstract ClassInterface
Used to declare properties, events, methods, and fields as well.Fields cannot be declared using interfaces.
Provides the partial implementation of functionalities that must be implemented by inheriting classes.Used to declare the behavior of an implementing class.
Different kinds of access modifiers like private, public, protected, etc. are supported.Only a public access modifier is supported.
It can contain static members.It does not contain static members.
Multiple inheritances cannot be achieved.Multiple inheritances are achieved.

15. How does managed code execute in the .NET framework?

Four main steps are included in the execution of the managed code. They are:

  1. Choosing a compiler that can execute the code written by a user
  2. Conversion of the code into Intermediate Language (IL) using a compiler
  3. IL gets pushed to CLR, which converts it into native code using JIT
  4. Native code is now executed using the .NET runtime
Summary

We know that .NET is a full-stack software development framework used to build large enterprise-scale and scalable software applications. It has a wide scope in the market. It is a flexible and user-friendly framework, that goes well along with other technologies. If you want to crack your interview for a .NET developer, go through these questions thoroughly. Consider our .NET Developer Training With Certification and Full-Stack .NET Developer Certification Training Program.

Read More:

Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at Scholarhat by DotNetTricks)

Shailendra Chauhan is the Founder and CEO at ScholarHat by DotNetTricks which is a brand when it comes to e-Learning. He provides training and consultation over an array of technologies like Cloud, .NET, Angular, React, Node, Microservices, Containers and Mobile Apps development. He has been awarded Microsoft MVP 8th time in a row (2016-2023). He has changed many lives with his writings and unique training programs. He has a number of most sought-after books to his name which has helped job aspirants in cracking tough interviews with ease.
Accept cookies & close this