.NET Interview Questions with Answers

  1. What is Polymorphism?

    • Answer: Polymorphism is the ability of a method, function, or object to take on different forms. It allows objects of different types to be treated as objects of a common supertype, and the correct method is invoked depending on the object’s actual type.

  2. What is Method Overloading?

    • Answer: Method overloading is when multiple methods in the same class have the same name but different parameters (either in type, number, or both). The appropriate method is chosen based on the method signature.

  3. What is the difference between ref and out?

    • Answer:

      • ref: The variable must be initialized before being passed to the method.

      • out: The variable does not need to be initialized before being passed to the method but must be assigned a value inside the method.

  4. What is the static method?

    • Answer: A static method belongs to the type itself rather than an instance of the class. It can be called without creating an instance of the class.

  5. Why multiple inheritance is not possible in C#?

    • Answer: C# does not support multiple inheritance to avoid complexities and ambiguities that may arise from inheriting the same method from multiple classes.

  6. What is a partial class?

    • Answer: A partial class is a class that is split across multiple files, enabling a team of developers to work on different parts of the class simultaneously.

  7. What is Enum?

    • Answer: An enum (short for enumeration) is a special "class" that represents a group of constants (unchangeable variables). Enums are used to represent a set of predefined values.

  8. What is the difference between Authorization and Authentication?

    • Answer:

      • Authentication verifies the identity of the user.

      • Authorization defines what an authenticated user is allowed to do (permissions).

  9. What is Abstract Interface?

    • Answer:

      • An abstract class can provide partial implementation of methods, whereas an interface only defines method signatures without any implementation.

      • A class can implement multiple interfaces but can inherit from only one abstract class.

  10. What is the difference between ReadOnly and Const?

    • Answer:

      • const: The value is set at compile-time and cannot be changed.

      • readonly: The value can be set either at the time of declaration or within the constructor, but not modified afterward.

  11. What is Sealed Class?

    • Answer: A sealed class is a class that cannot be inherited. It is used to prevent further derivation of the class.

  12. What is the difference between Boxed and Unboxed?

    • Answer:

      • Boxing is the process of converting a value type to an object type (e.g., converting an int to object).

      • Unboxing is the reverse process of converting an object back to a value type.


Software Development & Design

  1. What are delegates?

  • Answer: A delegate is a type that represents references to methods with a particular parameter list and return type. It allows methods to be passed as parameters.

  1. What is an Action Result in Web API?

    • Answer: An ActionResult is a base class for action results in ASP.NET Web API, representing the result of an HTTP request. It can return data, errors, or HTTP status codes.

  2. What is a trigger?

    • Answer: A trigger is a special kind of stored procedure that automatically executes when certain events occur in a database (e.g., insert, update, delete).

  3. What is a transaction?

    • Answer: A transaction is a sequence of operations that are treated as a single unit of work. Either all the operations in the transaction are completed successfully, or none are.

  4. What are indexes?

    • Answer: Indexes are used in databases to speed up the retrieval of rows based on the values of one or more columns.

  5. What is the difference between PUT and POST?

    • Answer:

      • POST is used to create a new resource.

      • PUT is used to update an existing resource.

  6. What is Web API OData?

    • Answer: OData (Open Data Protocol) is a protocol that allows clients to query and manipulate data using RESTful APIs. It supports features like filtering, sorting, and pagination.

  7. What is the difference between HTTP Module and HTTP Handler?

    • Answer:

      • HTTP Module: A module handles requests and responses globally.

      • HTTP Handler: A handler processes individual requests, typically for a specific file type.

  8. Where do we add authentication logic?

    • Answer: Authentication logic is generally added in the Global.asax file or in middleware for ASP.NET Core applications.

  9. Do you know OAuth? Explain how it works?

    • Answer: OAuth is an authorization framework that allows third-party applications to access a user’s resources without sharing their credentials. It works by issuing tokens that authorize specific actions on behalf of the user.

  10. What is the difference between HTTP Methods PUT, POST, DELETE, PATCH?

    • Answer:

      • POST: Used to create a resource.

      • PUT: Used to update an existing resource.

      • DELETE: Used to remove a resource.

      • PATCH: Used to partially update a resource.

  11. What are Filters?

    • Answer: Filters in ASP.NET are used to run code before or after an action method is executed. They are used for tasks like authorization, logging, and exception handling.

  12. What is Middleware in ASP.NET Core?

    • Answer: Middleware in ASP.NET Core is a pipeline that handles HTTP requests and responses. It allows you to add functionality like authentication, logging, and error handling.

  13. What is Dependency Injection (DI)?

    • Answer: Dependency Injection is a design pattern where objects or services are provided (injected) to a class, rather than the class creating the objects itself.

  14. What is a contractor?

    • Answer: A contractor is a professional who works on a temporary or project-specific basis rather than as a permanent employee. In programming, it could also refer to a method or a class constructor that is responsible for creating instances.


Database & SQL

  1. What is SQL Server Compact?

    • Answer: SQL Server Compact is a lightweight, embedded version of SQL Server used for desktop and mobile applications. It has a smaller footprint and fewer features than the full SQL Server.

  2. What is the difference between UNION vs UNION ALL?

    • Answer:

      • UNION combines results from two queries and removes duplicates.

      • UNION ALL combines results from two queries but does not remove duplicates.

  3. What is TCL in SQL?

    • Answer: Transaction Control Language (TCL) is used to manage transactions in a database. Common TCL commands include COMMIT, ROLLBACK, and SAVEPOINT.

  4. What is DENSE_RANK?

    • Answer: DENSE_RANK is a SQL window function that assigns a rank to each row within a partition of a result set, with no gaps in the ranking.

  5. What are JOINS in SQL?

    • Answer: JOINS are used to combine rows from two or more tables based on a related column between them. Types of JOINS include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.

  6. What are Keys in SQL?

    • Answer: Keys are constraints in SQL used to uniquely identify records in a table. Common keys are PRIMARY KEY, FOREIGN KEY, UNIQUE KEY, and INDEX.


Web Development & APIs

  1. How to consume an API?

    • Answer: APIs can be consumed by making HTTP requests (like GET, POST, PUT, DELETE) to the API endpoint using tools like Postman or directly from code using libraries like HttpClient in C#.

  2. What is Routing in ASP.NET?

    • Answer: Routing in ASP.NET is the process of determining how an HTTP request is handled by the application. It maps incoming requests to controller actions based on the URL pattern.

  3. How to Implement Authentication?

    • Answer: Authentication can be implemented using middleware or services in ASP.NET Core, such as Cookie Authentication, JWT (JSON Web Tokens), or OAuth.


Miscellaneous Concepts

  1. What is an Access Specifier?

    • Answer: Access specifiers define the visibility or accessibility of classes, methods, and variables. Common access specifiers are public, private, protected, and internal.

  2. What is a Sealed Class?

    • Answer: A sealed class is a class that cannot be inherited. It is used to prevent further derivation of the class.

  3. Page Lifecycle in Web Development?

    • Answer: In ASP.NET Web Forms, the page lifecycle involves multiple stages like Initialization, Load, Postback Handling, Rendering, and Unload. Each stage provides opportunities to customize the behavior of a page.



Comments

Popular posts from this blog

API development using .NET Core - ProductManagmentCRUD

Singleton Design Pattern Realtime Example of banking

Consume API in MVC Application