blog7

Top .NET Interview Questions & Answers – Advanced Edition

  • If you’re preparing for senior or mid-level .NET interviews, expect questions beyond syntax. Here are some advanced Q&A you should be ready for:

Questions & Answers

  • Que1: What is the difference between IEnumerable, IQueryable, and List in .NET?
  • Ans: IEnumerable works in-memory and is best for simple iteration.
  • Ans: IQueryable allows deferred execution and runs queries on the database side.
  • Ans: List is a concrete in-memory collection with indexing and modification support.
  • Que2: Explain the difference between Task, Thread, and ValueTask.
  • Ans: Thread: OS-level execution unit.
  • Ans: Task: Higher-level abstraction over threads for async operations.
  • Ans: ValueTask: Optimized for scenarios where the result may already be available, reducing allocations.
  • Que3: How does Dependency Injection (DI) work in .NET Core?
  • Ans: .NET Core has a built-in IoC container. Services are registered with lifetimes:
  • Ans: Singleton (one instance per application), Scoped (one instance per request)
  • Ans: Transient (new instance every time)
  • Ans: This promotes loose coupling and testability.
  • Que4: What’s the difference between struct and class in C#?
  • Ans: struct is a value type, stored on the stack, lightweight, and doesn’t support inheritance.
  • Ans: class is a reference type, stored on the heap, supports inheritance, and is more flexible.
  • Que5: How do you improve performance in an ASP.NET Core application?
  • Ans: Use caching (in-memory, distributed, response caching)
  • Ans: Use async/await properly
  • Ans: Optimize EF Core queries (projection, AsNoTracking())
  • Ans: Profile & monitor with Application Insights
  • Que6: What is IEnumerable vs IQueryable?
  • Ans: IEnumerable executes data in memory, while IQueryable translates queries into SQL and runs them at the database level. Use IQueryable for large datasets.
  • Que7: What is Dependency Injection in .NET?
  • Ans: A design pattern where dependencies are injected instead of created inside a class, improving testability and loose coupling. Built-in in ASP.NET Core.
  • Que8: What is async / await?
  • Ans: It allows writing non-blocking asynchronous code while keeping it readable and sequential.
  • Que9: Difference between Task and Thread?
  • Ans: A Thread is OS-level, while a Task is higher-level and managed by the .NET thread pool, making it more efficient.
  • Que10: What is Middleware in ASP.NET Core?
  • Ans: Middleware handles HTTP requests and responses in a pipeline (e.g., Authentication, Logging, Exception Handling).
  • Que11: What is EF Core?
  • Ans: An ORM that allows developers to work with databases using C# objects and LINQ instead of SQL.
  • Que12: What are Service Lifetimes?
  • Ans: Transient: New instance every time
  • Ans: Scoped: One instance per request
  • Ans: Singleton: One instance for the entire app
  • Que13: What is Garbage Collection?
  • Ans: Automatic memory management that removes unused objects to free memory.
  • Que14: What is REST?
  • Ans: A stateless architectural style using HTTP methods like GET, POST, PUT, and DELETE.
  • Que15: What is SOLID?
  • Ans: Five design principles that help build maintainable and scalable applications.