ASP.NET Interview Questions

ASP.NET Interview Questions


SOLID Principles

1. Single Responsibility Principle (SRP)

A class should have one and only one reason to change, meaning that a class should have only one job.

2. Open/Closed Principle (OCP)

Objects or entities should be open for extension but closed for modification.

3. Liskov Substitution Principle (LSP)

Every subclass or derived class should be substitutable for their base or parent class.

4. Interface Segregation Principle (ISP)

A client should never be forced to implement an interface it doesn't use or depend on methods it does not need.

5. Dependency Inversion Principle (DIP)

High-level modules should not depend on low-level modules; both should depend on abstractions.

Design Patterns

Structural Patterns

  • Adapter: Adapts one interface to another.
  • Bridge: Decouples an abstraction from its implementation so the two can vary independently.

Creational Patterns

  • Factory Pattern: Used to create instances of a single class and encapsulates the instantiation logic.
  • Abstract Factory Pattern: Used when you need to create related objects (e.g., GUI components) to maintain consistency.
  • Unit of Work: Manages database transactions to ensure consistency and integrity.

Behavioral Patterns

  • Mediator: Facilitates communication between different objects to minimize dependencies.
  • Observer: A subject maintains a list of its dependents and notifies them of any state changes.

Object-Oriented Programming (OOP) Concepts

  • Polymorphism:
  • Static: Achieved through overloading.
  • Dynamic: Achieved through overriding.
  • Encapsulation: Private variables with public getter and setter functions.
  • An abstract class allows you to create functionality that subclasses can implement or override.?
  • An interface only allows you to define functionality, not implement it. And whereas a class can extend only one abstract class, it can take advantage of multiple interfaces.

View Data vs ViewBag vs TempData

  • ViewData: Needs typecasting (similar to var).
  • ViewBag: No need for typecasting (late binding, similar to dynamic).
  • TempData: Used for passing data between two actions and is automatically destroyed if not preserved.

Generic Programming

  • Generics: Allows a class or method to work with multiple types of objects.
  • var vs dynamic:

var: Determined at compile time; type cannot change.

dynamic: Determined at runtime; type can change.

  • out vs ref

ref: Requires an assigned value before passing.

out: Value assignment is not required before passing.

Entity Framework (EF)

An ORM for .NET that allows working with data as domain-specific objects rather than tables and columns. It simplifies data-oriented application development by reducing boilerplate code.

Constructors in .NET

  • Default Constructor: No parameters.
  • Parameterized Constructor: Accepts parameters to initialize an object.
  • Copy Constructor: Initializes a new object with the values of an existing object.
  • Private Constructor: Used in singleton patterns to prevent object instantiation outside the class.
  • Static Constructor: Called automatically to initialize the class before the first instance is created; cannot be parameterized.

Key Notes:

  • A constructor cannot be abstract, final, or synchronized.
  • A class can only have one static constructor.
  • Constructors do not have a return type.

Promises vs Observables

  • Promise: Handles a single async event (either resolved or rejected).
  • Observable: Handles multiple events and can be canceled (more versatile for handling streams of data).

Common Language Runtime (CLR)

The CLR is the runtime environment for .NET applications, managing memory, code verification, security, and garbage collection. The JIT compiler converts Intermediate Language (IL) into machine code at runtime.

Ahead-of-time (AOT)

Ahead-of-time (AOT) compilation refers to an umbrella of technologies which generate code at application build time, instead of run-time. AOT is not new to .Net. Today we ship ReadyToRun for client and server scenarios, and Mono AOT for mobile and WASM. Native AOT brings full native pre-compilation to .Net desktop client and server scenarios

Dependency Injection

  • Loosely coupling of code
  • Runtime injection of dependencies
  • Singleton
  • Transient
  • Scoped

Task vs Thread

  • Thread: Represents a low-level execution flow in Windows.
  • Task: Higher-level abstraction, supporting cancellation tokens, parallelism, and result-returning mechanisms.
  • Tasks are managed by the runtime, while Threads are managed by the OS.

Dynamic Language Runtime (DLR)

The DLR adds dynamic language support to the CLR, allowing dynamic typing and execution in .NET applications.

Mutable vs Immutable

  • Mutable: Objects whose state can change after they are created.
  • Immutable: Objects that cannot be modified after creation.

IQueryable Vs IEnumerable

  • IQueryable: Executes queries in the database (e.g., where clause is translated to SQL).
  • IEnumerable: Fetches all records and performs filtering in-memory.

Boxing and Unboxing

  • Boxing: Converts a value type to a reference type.

   int i = 100;
  object obj = i;        


  • Unboxing: Converts a reference type back to a value type.

  int i = (int)obj;        


Miscellaneous Concepts

  • Value Types: Stored in stack (LIFO).
  • Reference Types: Stored in heap (random order).
  • Singleton: One instance per application cycle; private constructor.
  • Sealed: Cannot be inherited.
  • Static: Cannot be inherited or instantiated.
  • Session vs cookies?
  • Viewstate
  • JWT (3 required parts)?
  • Conventional vs Attribute Routing?
  • Data Reader,Data Adapter
  • Const vs Read-only
  • Managed Code vs Unmanaged code
  • Method Overloads vs Override
  • Validation Types in C#?
  • Encryption Decryption
  • Filters in mvc
  • Global Exception Filters
  • Middlewares in .Net Core
  • Early Binding: All child objects are bound at compile time.
  • Late Binding: Binding occurs during runtime.


Muhammad Furqan Azhar ????

Back-End Developer at MaanzAI

1 个月

Very informative

回复
Muhammad Fahad

Full-Stack .Net Developer C# |ASP.NET | MVC | .NET Core | Microservices |Azure

1 个月

Very helpful

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了