Top 50 .NET Interview Questions and Answers

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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).
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. What are extension methods?
    Extension methods allow adding new methods to existing types without modifying their source code.
  10. 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.
  11. What is Entity Framework?
    Entity Framework (EF) is an Object-Relational Mapper (ORM) that allows developers to work with a database using .NET objects.
  12. 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.
  13. What are async and await in C#?
    async and await are keywords used for asynchronous programming, allowing non-blocking execution of code.
  14. What is garbage collection in .NET?
    Garbage collection automatically frees memory by removing objects that are no longer in use.
  15. What is middleware in ASP.NET Core?
    Middleware is software that sits in the HTTP request pipeline to handle requests and responses.
  16. What are the types of authentication in ASP.NET Core?
    Types include cookie authentication, JWT bearer authentication, and OAuth/OpenID Connect.
  17. What is the difference between authentication and authorization?
    Authentication verifies a user’s identity, while authorization determines the resources the user can access.
  18. What is routing in ASP.NET Core?
    Routing maps incoming requests to the correct controller action.
  19. 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.
  20. What is model binding in ASP.NET Core?
    Model binding maps incoming request data to action method parameters.
  21. What is the difference between synchronous and asynchronous calls?
    Synchronous calls block until completion, while asynchronous calls allow other operations to run while waiting.
  22. 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.
  23. 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.
  24. What is a ViewModel?
    A ViewModel is a class specifically created to hold data for the view.
  25. What is the repository pattern?
    It is a design pattern that abstracts data access, making the application more testable and maintainable.
  26. 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.
  27. What is the difference between IEnumberable and IQueryable?
    IEnumerable executes queries in memory, while IQueryable can execute queries on a remote data source.
  28. 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.
  29. What is the difference between string and StringBuilder?
    string is immutable, while StringBuilder is mutable and better for frequent modifications.
  30. What is reflection in .NET?
    Reflection allows inspection of metadata about assemblies, modules, and types at runtime.
  31. What is serialization?
    Serialization is converting an object into a format that can be stored or transmitted.
  32. 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.
  33. What is the Global.asax file used for?
    It contains application-level events like Application_Start and Application_End.
  34. What are action results in ASP.NET MVC/Core?
    They are return types from controller actions, such as ViewResult, JsonResult, or FileResult.
  35. What is middleware ordering in ASP.NET Core?
    The order of middleware registration determines how requests and responses are processed.
  36. 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.
  37. What is CORS?
    Cross-Origin Resource Sharing is a mechanism that allows controlled access to resources from different domains.
  38. What is the difference between API controller and MVC controller?
    API controllers return data (JSON/XML) by default, while MVC controllers return views.
  39. What is Swagger?
    Swagger is an open-source tool for documenting and testing APIs.
  40. What is model validation in ASP.NET Core?
    It ensures that input data meets certain rules before processing.
  41. What are tag helpers in ASP.NET Core?
    Tag helpers enable server-side code to participate in creating and rendering HTML elements.
  42. 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.
  43. What is the difference between PUT and PATCH?
    PUT replaces a resource entirely, while PATCH updates only part of a resource.
  44. What is async streaming in C# 8?
    Async streaming allows processing data streams asynchronously using IAsyncEnumerable.
  45. What is the difference between throw and throw ex?
    throw preserves the original stack trace, while throw ex resets it.
  46. What is Kestrel?
    Kestrel is the cross-platform web server used in ASP.NET Core.
  47. 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.
  48. What is SignalR?
    SignalR is a library for adding real-time web functionality to applications.
  49. What is gRPC in .NET?
    gRPC is a high-performance, open-source framework for remote procedure calls.
  50. What is memory leak in .NET?
    A memory leak occurs when objects are not properly disposed and remain in memory unnecessarily.
  51. What is IDisposable in C#?
    IDisposable defines the Dispose method for releasing unmanaged resources.

Comments