interview-questions
  1. net-framework-interview-questions

.Net Framework Interview Questions & Answers


Basics of .NET Framework:

  1. What is the .NET Framework?

    • Answer: The .NET Framework is a development platform for building Windows applications. It provides a comprehensive and consistent programming model, a common set of APIs, and a runtime environment for executing applications.
  2. Explain the Common Language Runtime (CLR).

    • Answer: The CLR is the execution engine of the .NET Framework. It manages memory, handles exceptions, performs garbage collection, and provides services such as security and threading.
  3. What are the key components of the .NET Framework?

    • Answer: The key components include the Common Language Runtime (CLR), the Base Class Library (BCL), and the Just-In-Time (JIT) compiler.
  4. Differentiate between .NET Framework, .NET Core, and .NET 5/6.

    • Answer: .NET Framework is the traditional framework for Windows applications. .NET Core is a cross-platform, open-source framework. .NET 5/6 is the unified platform that combines the best features of both .NET Framework and .NET Core.
  5. What is the Global Assembly Cache (GAC)?

    • Answer: The GAC is a repository of shared assemblies that can be accessed by multiple applications on a computer. It helps in versioning and avoids conflicts between different versions of the same assembly.

C# Language:

  1. Explain the difference between value types and reference types in C#.

    • Answer: Value types store their data directly, while reference types store a reference to the location in memory where the data is stored. Value types include simple types like int and float, while reference types include objects and arrays.
  2. What is the purpose of the 'using' statement in C#?

    • Answer: The 'using' statement is used for automatic resource management. It ensures that the Dispose method of an object is called when the object is no longer needed.
  3. What is the 'var' keyword in C#?

    • Answer: The 'var' keyword is used to implicitly declare a local variable. The compiler determines the type of the variable based on the assigned value.
  4. Explain the concept of nullable types in C#.

    • Answer: Nullable types allow variables to have a value of null in addition to their normal range of values. They are declared using the '?' modifier, like 'int?'.
  5. What is the 'async' and 'await' keyword in C#?

    • Answer: 'async' and 'await' are used for asynchronous programming in C#. The 'async' keyword indicates that a method contains asynchronous operations, and 'await' is used to wait for the completion of an asynchronous task.

Object-Oriented Programming (OOP):

  1. What are the four pillars of OOP?

    • Answer: Encapsulation, Inheritance, Abstraction, and Polymorphism are the four pillars of object-oriented programming.
  2. Explain the concept of encapsulation.

    • Answer: Encapsulation is the bundling of data and the methods that operate on that data into a single unit, often referred to as a class. It helps in hiding the internal implementation details.
  3. What is inheritance, and how does it promote code reuse?

    • Answer: Inheritance is a mechanism that allows a class to inherit the properties and behaviors of another class. It promotes code reuse by allowing a new class (derived class) to use the functionalities of an existing class (base class).
  4. Define abstraction in the context of OOP.

    • Answer: Abstraction is the process of simplifying complex systems by modeling classes based on their essential properties and behaviors. It hides the unnecessary details and focuses on what an object does.
  5. Explain polymorphism and its types in OOP.

    • Answer: Polymorphism allows objects of different types to be treated as objects of a common type. Types of polymorphism include compile-time (method overloading) and runtime (method overriding) polymorphism.

ASP.NET:

  1. What is ASP.NET, and how does it differ from ASP.NET Core?

    • Answer: ASP.NET is a web application framework for building web pages and web services. ASP.NET Core is a cross-platform, high-performance, open-source framework, and it's a significant redesign of the original ASP.NET.
  2. Explain the role of the Web.config file in ASP.NET.

    • Answer: The Web.config file in ASP.NET contains configuration settings for a web application, including database connections, authentication settings, and custom error pages.
  3. What is the ASP.NET Page Life Cycle?

    • Answer: The ASP.NET Page Life Cycle is the series of events that occur during the processing of an ASP.NET page, from initialization to rendering and unloading.
  4. Differentiate between ASP.NET Web Forms and ASP.NET MVC.

    • Answer: Web Forms is a traditional event-driven model for building web applications, while MVC (Model-View-Controller) is an architectural pattern that separates an application into three interconnected components.
  5. What is Razor syntax in ASP.NET?

    • Answer: Razor syntax is a markup syntax used to embed server-based code into web pages. It is concise and easy to read, providing a smooth transition between HTML and C# code.

ADO.NET:

  1. What is ADO.NET, and how does it differ from Entity Framework?

    • Answer: ADO.NET is a data access technology in the .NET Framework for interacting with databases. Entity Framework is an Object-Relational Mapping (ORM) framework that simplifies data access by using object-oriented techniques.
  2. Explain the purpose of the SqlConnection class in ADO.NET.

    • Answer: SqlConnection is a class in ADO.NET that represents a connection to a SQL Server database. It provides methods for opening, closing, and managing the connection.
  3. What is the role of the SqlCommand class in ADO.NET?

    • Answer: SqlCommand is used to execute SQL commands against a database. It can be used to execute queries, stored procedures, and perform other database operations.
  4. How does ADO.NET prevent SQL injection attacks?

    • Answer: ADO.NET supports parameterized queries, which use parameters to separate SQL code from user input. This helps prevent SQL injection attacks by ensuring that user input is treated as data, not executable code.

LINQ:

  1. What is LINQ, and how does it simplify data access in .NET?

    • Answer: LINQ (Language Integrated Query) is a set of features that adds query capabilities to C# and VB.NET. It provides a unified way to query and manipulate data from different sources, such as databases, collections, and XML.
  2. Explain the difference between IQueryable and IEnumerable in LINQ.

    • Answer: IEnumerable represents a forward-only cursor of data, suitable for querying in-memory collections. IQueryable represents a query that can be executed against a specific data source, such as a database.
  3. What is deferred execution in LINQ?

    • Answer: Deferred execution means that

the execution of a LINQ query is delayed until the results are actually needed. It allows the optimization of queries and minimizes the amount of data retrieved.

Entity Framework:

  1. What is Entity Framework, and how does it relate to databases?

    • Answer: Entity Framework is an Object-Relational Mapping (ORM) framework for .NET. It enables developers to work with databases using object-oriented techniques, mapping database entities to .NET objects.
  2. Explain the Code First approach in Entity Framework.

    • Answer: Code First is an approach in Entity Framework where the database is created based on the code (C# classes) rather than the other way around. Developers define classes, and EF generates the database schema.
  3. What is the purpose of DbSet in Entity Framework?

    • Answer: DbSet is a property in a DbContext class that represents a collection of entities of a particular type. It provides methods for querying, adding, updating, and deleting entities.

.NET Core and ASP.NET Core:

  1. What is .NET Core, and what are its key advantages?

    • Answer: .NET Core is a cross-platform, open-source framework for building modern, cloud-based, and high-performance applications. Key advantages include cross-platform compatibility, modularity, and performance improvements.
  2. Explain the role of the Startup class in ASP.NET Core.

    • Answer: The Startup class in ASP.NET Core is used to configure services and the application's request processing pipeline. It contains methods such as ConfigureServices and Configure.
  3. What is Kestrel in the context of ASP.NET Core?

    • Answer: Kestrel is a cross-platform, lightweight, and open-source web server built for hosting ASP.NET Core applications. It is the default web server for ASP.NET Core.

Dependency Injection in .NET:

  1. What is dependency injection, and why is it beneficial in .NET?

    • Answer: Dependency injection is a design pattern where dependencies are injected into a class rather than being created within the class. It promotes loose coupling, testability, and maintainability.
  2. Explain the role of the IServiceCollection interface in .NET Core dependency injection.

    • Answer: IServiceCollection is used to define a contract for a collection of service descriptors. It is part of the ASP.NET Core dependency injection system and is used to register and configure services.

Unit Testing in .NET:

  1. What is unit testing, and how is it implemented in .NET?

    • Answer: Unit testing involves testing individual units or components of a software application in isolation. In .NET, unit testing is often done using frameworks like NUnit, xUnit, or MSTest.
  2. Explain the concept of mocking in unit testing.

    • Answer: Mocking involves creating objects that simulate the behavior of real objects. It is useful in unit testing to isolate the unit being tested and control its dependencies.

Security in .NET:

  1. How can you secure sensitive information in .NET applications?

    • Answer: Sensitive information in .NET applications can be secured using techniques such as encryption, secure storage mechanisms, and protecting sensitive data in transit.
  2. Explain the concept of Cross-Site Scripting (XSS) and how to prevent it in .NET.

    • Answer: XSS is a security vulnerability that allows attackers to inject malicious scripts into web pages viewed by other users. In .NET, preventing XSS involves proper input validation, encoding, and using AntiXSS libraries.

.NET Core and Docker:

  1. How can you containerize a .NET Core application using Docker?
    • Answer: Containerizing a .NET Core application involves creating a Dockerfile, specifying the application, dependencies, and configuration. You then build a Docker image and run containers based on that image.

Web Services and APIs:

  1. What is the role of ASP.NET Web API in building RESTful services?

    • Answer: ASP.NET Web API is a framework for building HTTP services that can be consumed by a variety of clients. It is commonly used for building RESTful APIs.
  2. How can you handle cross-origin requests (CORS) in ASP.NET Web API?

    • Answer: CORS can be configured in ASP.NET Web API using the EnableCors attribute, allowing or denying cross-origin requests based on specified policies.
  3. Explain the difference between SOAP and RESTful services.

    • Answer: SOAP is a protocol for exchanging structured information in web services, while REST is an architectural style that uses standard HTTP methods for communication. RESTful services are often simpler and more scalable.
  4. What is Swagger, and how is it used in ASP.NET Web API?

    • Answer: Swagger is a tool for documenting and testing APIs. In ASP.NET Web API, Swagger can generate an interactive API documentation page, making it easier for developers to understand and test the API.

.NET Core Identity:

  1. What is .NET Core Identity, and how does it handle user authentication and authorization?
    • Answer: .NET Core Identity is a membership system that adds login functionality to .NET Core applications. It provides APIs for user registration, login, and role-based authorization.

.NET Core MVC:

  1. What is .NET Core MVC, and how does it differ from ASP.NET MVC?
    • Answer: .NET Core MVC is a web application framework for building modern, cloud-based, and cross-platform applications. It is a part of .NET Core and is a redesign of ASP.NET MVC with improved performance and cross-platform support.

.NET Core Middleware:

  1. Explain the concept of middleware in .NET Core.
    • Answer: Middleware in .NET Core is a component that can handle requests and responses in the application's request processing pipeline. It allows for customizing the behavior of the application.

.NET Core Logging:

  1. What is logging, and how is it implemented in .NET Core?
    • Answer: Logging is the process of recording events and messages during the execution of an application. In .NET Core, logging is achieved using the built-in ILogger interface and various logging providers.

.NET Core Configuration:

  1. What is configuration in .NET Core, and how is it managed?
    • Answer: Configuration in .NET Core refers to the settings and parameters used by an application. It is managed through the IConfiguration interface, which allows developers to access configuration values from various sources.

.NET Core Globalization and Localization:

  1. How can you implement globalization and localization in .NET Core?
    • Answer: Globalization and localization in .NET Core involve providing resources for different languages and cultures. It can be implemented using resource files, the IStringLocalizer interface, and the use of the RequestLocalization middleware.