All interview guides

C# Interview Questions and Answers

24 questions that come up in C# technical interviews, each with the answer and an explanation of why it is right.

Test yourself — 90 question bank

1. What is reflection?

Advanced

Answer: Examines and manipulates types at runtime

Reflection examines and manipulates types, methods, properties at runtime. Use System.Reflection namespace. Enables dynamic invocation, attribute reading. Performance cost.

2. What is LINQ?

Intermediate

Answer: Language Integrated Query for querying collections

LINQ (Language Integrated Query) provides query capabilities for collections. Supports query syntax and method syntax. Works with IEnumerable and IQueryable.

3. What is C#?

Beginner

Answer: Modern, object-oriented programming language by Microsoft

C# is a modern, object-oriented, type-safe programming language developed by Microsoft. It runs on .NET platform and is used for various applications.

4. What is the Garbage Collector?

Advanced

Answer: Automatic memory management system

Garbage Collector (GC) automatically manages memory. Reclaims unused objects. Runs in generations (0, 1, 2). Can be tuned but generally leave to runtime.

5. What is the difference between IEnumerable and IQueryable?

Intermediate

Answer: IEnumerable in-memory, IQueryable for databases

IEnumerable executes queries in-memory (LINQ to Objects). IQueryable translates to database queries (LINQ to SQL/EF). IQueryable supports deferred execution with expression trees.

6. What is a delegate?

Intermediate

Answer: Type-safe function pointer

Delegate is type-safe function pointer. References methods with matching signature. Enables callbacks, events, method passing. Foundation for events and lambdas.

7. What are GC generations?

Advanced

Answer: Gen 0 (young), Gen 1 (medium), Gen 2 (old)

GC uses three generations: Gen 0 (newly allocated, collected frequently), Gen 1 (survived one collection), Gen 2 (long-lived objects). Optimizes collection.

8. What is the difference between int and Int32?

Beginner

Answer: No difference, int is alias for Int32

int is a C# keyword that is an alias for System.Int32. They are completely interchangeable. int is preferred for readability.

9. What is an event?

Intermediate

Answer: Notification mechanism using delegates

Events provide notification mechanism using delegates. Publishers raise events, subscribers handle them. Uses += to subscribe, -= to unsubscribe. Based on observer pattern.

10. What is IDisposable?

Advanced

Answer: Interface for releasing unmanaged resources

IDisposable interface provides mechanism for releasing unmanaged resources (file handles, database connections). Implement Dispose() method. Use with using statement.

11. What is the Dispose pattern?

Advanced

Answer: Pattern for deterministic resource cleanup

Dispose pattern implements IDisposable with protected virtual Dispose(bool) method. Handles both managed and unmanaged resources. Prevents finalization if disposed.

12. What is a lambda expression?

Intermediate

Answer: Anonymous function with concise syntax

Lambda expression is anonymous function using => operator. Example: x => x * 2. Used with LINQ, delegates, expression trees. More concise than anonymous methods.

13. What is async/await?

Intermediate

Answer: Asynchronous programming pattern

async/await enables asynchronous programming. async methods return Task, await suspends execution without blocking thread. Improves responsiveness and scalability.

14. What is the difference between == and Equals()?

Beginner

Answer: == compares references, Equals() compares values

For reference types, == typically compares references (same object), Equals() compares values (content). Can be overridden for custom behavior.

15. What is finalization?

Advanced

Answer: Cleanup before garbage collection via finalizer

Finalization runs cleanup code before GC reclaims memory. Use ~ClassName() syntax. Non-deterministic timing. Avoid unless necessary for unmanaged resources.

16. What is weak reference?

Advanced

Answer: Reference not preventing garbage collection

Weak reference allows referencing objects without preventing garbage collection. Use WeakReference class. Useful for caches, large object graphs.

17. What is a class?

Beginner

Answer: Blueprint for creating objects

A class is a blueprint/template for creating objects. It defines properties, methods, and events. Core concept of object-oriented programming.

18. What is Task?

Intermediate

Answer: Represents asynchronous operation

Task represents asynchronous operation. Can return value (Task<T>) or no value (Task). Use Task.Run() for CPU-bound work, async methods for I/O-bound.

19. What is a generic type?

Intermediate

Answer: Type with type parameters enabling type safety and reuse

Generic types use type parameters for type safety and code reuse. Example: List<T>. Compiler generates type-specific code. Avoid boxing, runtime type checking.

20. What is an object?

Beginner

Answer: Instance of a class

An object is an instance of a class. Created using new keyword. Contains actual data and can call methods defined in the class.

21. What is span<T>?

Advanced

Answer: Type-safe, stack-allocated memory view

Span<T> is type-safe, stack-allocated view over contiguous memory. Zero-copy operations. High performance. Cannot be stored on heap. Use for performance-critical code.

22. What is memory<T>?

Advanced

Answer: Heap-allocatable memory view like Span

Memory<T> is heap-allocatable alternative to Span<T>. Can be stored in fields, async methods. Represents contiguous region of memory. Use with async operations.

23. What is inheritance?

Beginner

Answer: Mechanism where class inherits members from base class

Inheritance allows a class to inherit members (fields, properties, methods) from a base class. Promotes code reuse. Use : syntax.

24. What is a collection?

Intermediate

Answer: Data structure storing multiple items

Collections store multiple items. Common: List<T>, Dictionary<K,V>, HashSet<T>, Queue<T>, Stack<T>. More flexible than arrays. Support generics.

Ready to test yourself?

The full C# bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.

Take the C# quiz