Top 50 .NET Interview Questions and Answers
Here is a collection of the most frequently asked .NET interview questions along with detailed answers. This will help you prepare for both technical rounds and real-world scenario-based interviews.
-
What is the .NET Framework?
The .NET Framework is a software development platform developed by Microsoft. It includes the Common Language Runtime (CLR) and the .NET Framework Class Library, which provide a wide range of functionalities for building applications. -
What is the CLR?
The Common Language Runtime (CLR) is the execution engine for .NET applications. It handles memory management, security, exception handling, and garbage collection. -
What is the difference between .NET Framework and .NET Core?
.NET Framework is Windows-only, while .NET Core is cross-platform, open-source, and can run on Windows, Linux, and macOS. -
What is the difference between value types and reference types?
Value types store data directly and are stored in the stack (e.g., int, struct), while reference types store a reference to the data, which is stored in the heap (e.g., class, object). -
What is the difference between boxing and unboxing?
Boxing is converting a value type to a reference type, and unboxing is converting a reference type back to a value type. -
What is the difference between an abstract class and an interface?
Abstract classes can have implementation and fields, while interfaces can only have declarations (until C# 8 default methods). A class can inherit only one abstract class but can implement multiple interfaces. -
What is the difference between const and readonly in C#?
const values are compile-time constants and must be assigned at declaration. readonly values are runtime constants and can be assigned in the constructor. -
What is dependency injection?
Dependency Injection (DI) is a design pattern used to achieve loose coupling by injecting dependencies from the outside rather than creating them inside a class. -
What are extension methods?
Extension methods allow adding new methods to existing types without modifying their source code. -
What is LINQ?
Language Integrated Query (LINQ) is a set of features for querying data from different sources (objects, databases, XML) in a consistent syntax. -
What is Entity Framework?
Entity Framework (EF) is an Object-Relational Mapper (ORM) that allows developers to work with a database using .NET objects. -
What is the difference between EF Core and EF 6?
EF Core is lightweight, cross-platform, and open-source, while EF 6 is Windows-only and feature-rich but not cross-platform. -
What are async and await in C#?
async and await are keywords used for asynchronous programming, allowing non-blocking execution of code. -
What is garbage collection in .NET?
Garbage collection automatically frees memory by removing objects that are no longer in use. -
What is middleware in ASP.NET Core?
Middleware is software that sits in the HTTP request pipeline to handle requests and responses. -
What are the types of authentication in ASP.NET Core?
Types include cookie authentication, JWT bearer authentication, and OAuth/OpenID Connect. -
What is the difference between authentication and authorization?
Authentication verifies a user’s identity, while authorization determines the resources the user can access. -
What is routing in ASP.NET Core?
Routing maps incoming requests to the correct controller action. -
What is the difference between TempData, ViewData, and ViewBag?
ViewData and ViewBag are used to pass data from controller to view (ViewData is a dictionary, ViewBag is dynamic). TempData persists until the next request. -
What is model binding in ASP.NET Core?
Model binding maps incoming request data to action method parameters. -
What is the difference between synchronous and asynchronous calls?
Synchronous calls block until completion, while asynchronous calls allow other operations to run while waiting. -
What is the difference between Task and Thread?
Task is a higher-level abstraction that can use threads under the hood, adding features like continuation and cancellation. -
What are filters in ASP.NET MVC/Core?
Filters are used to execute code before or after specific stages in the request pipeline, such as authorization, action execution, and result execution. -
What is a ViewModel?
A ViewModel is a class specifically created to hold data for the view. -
What is the repository pattern?
It is a design pattern that abstracts data access, making the application more testable and maintainable. -
What is the unit of work pattern?
It is a pattern that maintains a list of operations to be performed and commits them in a single transaction. -
What is the difference between IEnumberable and IQueryable?
IEnumerable executes queries in memory, while IQueryable can execute queries on a remote data source. -
What is the difference between FirstOrDefault and SingleOrDefault?
FirstOrDefault returns the first matching element or null if none exist. SingleOrDefault throws an exception if more than one element is found. -
What is the difference between string and StringBuilder?
string is immutable, while StringBuilder is mutable and better for frequent modifications. -
What is reflection in .NET?
Reflection allows inspection of metadata about assemblies, modules, and types at runtime. -
What is serialization?
Serialization is converting an object into a format that can be stored or transmitted. -
What is the difference between XML and JSON serialization?
XML is more verbose and supports attributes, while JSON is lightweight and faster for web communication. -
What is the Global.asax file used for?
It contains application-level events like Application_Start and Application_End. -
What are action results in ASP.NET MVC/Core?
They are return types from controller actions, such as ViewResult, JsonResult, or FileResult. -
What is middleware ordering in ASP.NET Core?
The order of middleware registration determines how requests and responses are processed. -
What is the difference between public, private, protected, and internal access modifiers?
public – accessible everywhere; private – only within the class; protected – within the class and derived classes; internal – within the same assembly. -
What is CORS?
Cross-Origin Resource Sharing is a mechanism that allows controlled access to resources from different domains. -
What is the difference between API controller and MVC controller?
API controllers return data (JSON/XML) by default, while MVC controllers return views. -
What is Swagger?
Swagger is an open-source tool for documenting and testing APIs. -
What is model validation in ASP.NET Core?
It ensures that input data meets certain rules before processing. -
What are tag helpers in ASP.NET Core?
Tag helpers enable server-side code to participate in creating and rendering HTML elements. -
What is the difference between GET and POST?
GET retrieves data and should not modify server state. POST sends data to be processed and can modify server state. -
What is the difference between PUT and PATCH?
PUT replaces a resource entirely, while PATCH updates only part of a resource. -
What is async streaming in C# 8?
Async streaming allows processing data streams asynchronously using IAsyncEnumerable. -
What is the difference between throw and throw ex?
throw preserves the original stack trace, while throw ex resets it. -
What is Kestrel?
Kestrel is the cross-platform web server used in ASP.NET Core. -
What is the difference between .NET Standard and .NET Core?
.NET Standard is a specification for APIs available across all .NET implementations. .NET Core is a specific implementation of .NET. -
What is SignalR?
SignalR is a library for adding real-time web functionality to applications. -
What is gRPC in .NET?
gRPC is a high-performance, open-source framework for remote procedure calls. -
What is memory leak in .NET?
A memory leak occurs when objects are not properly disposed and remain in memory unnecessarily. -
What is IDisposable in C#?
IDisposable defines the Dispose method for releasing unmanaged resources.
Comments
Post a Comment