Top 50 C# Intermediate Interview Questions and Answers - Textnotes

Top 50 C# Intermediate Interview Questions and Answers


A collection of the most important intermediate C# interview questions covering OOP, delegates, LINQ, collections, async/await, SOLID, generics, memory management, and .NET internals.

1. What is the difference between IEnumerable and IQueryable?

  1. IEnumerable: Executes queries in memory (LINQ to Objects).
  2. IQueryable: Executes queries in database (LINQ to SQL/EF).


2. What is the difference between ref and out?

  1. ref: Must be initialized before passing.
  2. out: Must be assigned inside the method.


3. What are Generics in C#?

A feature that allows type-safe data structures without boxing/unboxing.

Example: List<T>.


4. What is the difference between Interface and Abstract Class?

  1. Interface: Only declarations.
  2. Abstract class: Can have implementation + abstract methods.
  3. A class can implement multiple interfaces but only inherit one abstract class.


5. What is a Delegate?

A type-safe pointer to a method.


6. What is a Multicast Delegate?

A delegate that can hold multiple methods using +=.


7. What is an Event?

A wrapper around delegates used for publish–subscribe communication.


8. What is the difference between Func, Action, and Predicate?

  1. Func: returns value
  2. Action: returns void
  3. Predicate: returns bool


9. What is Dependency Injection (DI)?

A design pattern to remove class dependencies using:

  1. Constructor injection
  2. Property injection
  3. Method injection


10. What is SOLID in C#?

Five principles:

S – Single Responsibility

O – Open/Closed

L – Liskov Substitution

I – Interface Segregation

D – Dependency Inversion


11. What is Boxing/Unboxing?

  1. Boxing: Value → Reference
  2. Unboxing: Reference → Value


12. Difference between String and StringBuilder?

  1. String is immutable.
  2. StringBuilder is mutable, faster for modifications.


13. What is Extension Method?

Adds new methods to existing types without modifying them using this keyword.


14. What is Anonymous Method?

A method without a name defined using the delegate keyword.


15. What is Lambda Expression?

A shorthand anonymous function using =>.


16. What is Var vs Dynamic?

  1. var: compile-time type
  2. dynamic: runtime type


17. What is the difference between const and readonly?

  1. const: compile-time constant
  2. readonly: runtime constant


18. What is Polymorphism?

Method overloading (compile-time) & method overriding (run-time).


19. What is Shadowing (new keyword)?

Hiding base class method using new.


20. What is Virtual Keyword?

Allows a method to be overridden in derived classes.


21. What is Abstract Method?

A method declared but not implemented in abstract class.


22. What is Interface Default Implementation (.NET 8+)?

Interfaces can contain method bodies using default keyword.


23. What is Thread?

A lightweight process used for parallel execution.


24. What is Thread Pool?

Pre-created worker threads managed by CLR for performance.


25. What is Deadlock?

Two threads waiting indefinitely for each other’s resources.


26. What is Async/Await?

Used for non-blocking asynchronous programming.


27. What is Task Parallel Library (TPL)?

A set of APIs for parallel processing using Task.


28. Difference between Task and Thread?

  1. Task: higher-level abstraction
  2. Thread: low-level OS thread


29. What is Lock in C#?

A mechanism to prevent multiple threads accessing shared resources.


30. What is Monitor Class?

A more advanced locking mechanism than lock keyword.


31. What is Garbage Collection?

Automatic memory cleanup in .NET.


32. What are GC Generations?

  1. Gen 0
  2. Gen 1
  3. Gen 2
  4. Higher gen = older objects.


33. What is IDisposable Interface?

Used to release unmanaged resources using Dispose().


34. What is Using Statement?

Automatically calls Dispose().


35. What is Managed vs Unmanaged Code?

  1. Managed: controlled by CLR
  2. Unmanaged: outside CLR (COM, Win32)


36. What is Reflection?

Allows inspection of types at runtime.


37. What is late binding?

Type resolved at runtime using reflection/dynamic.


38. What is Attribute in C#?

Metadata applied to classes/methods like [Obsolete].


39. What is Serialization?

Converting object → data format (JSON, XML).

Opposite: Deserialization.


40. What is async state machine?

Compiler converts async/await into a state machine.


41. What is LINQ?

Language Integrated Query used for data querying.


42. Types of LINQ?

  1. LINQ to Objects
  2. LINQ to SQL
  3. LINQ to Entities
  4. LINQ to XML


43. What is Deferred Execution?

Query executes only when iterated.


44. What is Immediate Execution?

Query executed immediately using methods like:

  1. ToList()
  2. Count()
  3. First()


45. What are Joins in LINQ?

Inner, Left, Right, Full, Group Join.


46. What is PLINQ?

Parallel LINQ for multi-threaded queries.


47. What are Collections in C#?

  1. List
  2. Dictionary
  3. HashSet
  4. Queue
  5. Stack


48. Difference between List and Dictionary?

  1. List: index-based
  2. Dictionary: key-value pairs


49. What is Immutable Collection?

Collection whose elements cannot be changed. Available in System.Collections.Immutable.


50. What are Tuples in C#?

Lightweight structure to store multiple values.

Example:

(var id, var name) = GetData();