Programming Languages

C# interview questions

C# interviews often assess a candidate's understanding of object-oriented principles, memory management (value vs. reference types), common language features like generics and LINQ, and modern asynchronous programming patterns. Interviewers look for practical application and problem-solving skills using the .NET ecosystem.

15 questions (3 easy · 8 medium · 4 hard), each with what a strong answer covers and where people lose the point. Free to read, no account.

On this page (15 questions)
  1. 1.Explain the four pillars of Object-Oriented Programming (OOP) and provide a simple C# example for each.
  2. 2.What is the fundamental difference between value types and reference types in C#? Provide examples of each and explain their memory allocation.
  3. 3.Compare and contrast interfaces and abstract classes in C#. When would you choose one over the other?
  4. 4.What are generics in C# and what problems do they solve? Provide an example of a generic class or method.
  5. 5.Explain LINQ (Language Integrated Query) in C# and demonstrate its use with a simple query on a collection of objects.
  6. 6.Describe how `async` and `await` work in C# to enable asynchronous programming. What are the benefits and potential pitfalls?
  7. 7.What is the `IDisposable` interface and the `using` statement in C#? When and why would you use them?
  8. 8.Explain boxing and unboxing in C#. Provide a code example and discuss their performance implications.
  9. 9.What are delegates in C# and how are they related to events? Provide a simple example of using a delegate.
  10. 10.Explain the concept of static members (fields, methods, classes) in C#. When would you use them, and what are their limitations?
  11. 11.Describe a common deadlock scenario that can occur when mixing `async`/`await` with synchronous blocking calls (e.g., `.Result` or `.Wait()`). How can it be avoided?
  12. 12.What is Reflection in C#? Provide at least two practical use cases where Reflection would be beneficial.
  13. 13.Explain how garbage collection works in .NET. What are generations, and how do they optimize the process?
  14. 14.What are extension methods in C#? Explain their purpose and provide an example. Discuss design considerations when creating them.
  15. 15.When should you choose a `struct` over a `class` in C#? What are the trade-offs?

1.Explain the four pillars of Object-Oriented Programming (OOP) and provide a simple C# example for each.

Warm-up

What a strong answer covers

  • Define Encapsulation: bundling data and methods, restricting direct access (e.g., private fields with public properties).
  • Define Inheritance: creating new classes from existing ones, reusing code (e.g., `Dog` inherits from `Animal`).
  • Define Polymorphism: objects of different classes treated as objects of a common type (e.g., method overriding, interface implementation).
  • Define Abstraction: showing essential information, hiding implementation details (e.g., abstract classes, interfaces).

Where people lose the point

  • Confusing abstraction with encapsulation, or inheritance with polymorphism.
  • Providing examples that don't clearly demonstrate the specific pillar.
  • Failing to explain the 'why' behind each pillar's benefit.
Link to this question

2.What is the fundamental difference between value types and reference types in C#? Provide examples of each and explain their memory allocation.

Warm-up

What a strong answer covers

  • Value types store their data directly; reference types store a reference to their data.
  • Value types are typically allocated on the stack; reference types are allocated on the heap.
  • Examples of value types: `int`, `bool`, `struct`, `enum`. Explain that assignment creates a copy.
  • Examples of reference types: `class`, `string`, `array`, `delegate`. Explain that assignment copies the reference, not the data.

Where people lose the point

  • Incorrectly stating where `string` is allocated (it's a reference type, heap).
  • Failing to explain the implications of assignment (copy vs. shared reference).
  • Confusing `struct` with `class` in terms of memory behavior.
Link to this question

3.Compare and contrast interfaces and abstract classes in C#. When would you choose one over the other?

Core

What a strong answer covers

  • Interfaces define a contract (what a class can do) and can only contain declarations (methods, properties, events, indexers).
  • Abstract classes can provide partial implementation, contain fields, constructors, and non-abstract methods.
  • A class can implement multiple interfaces but can inherit from only one abstract class.
  • Choose an interface for defining capabilities or contracts across unrelated classes; choose an abstract class for providing a common base implementation for related classes.

Where people lose the point

  • Stating that interfaces can have implementation (pre-C# 8) or fields.
  • Not mentioning the single inheritance limitation for abstract classes.
  • Failing to provide clear use-case scenarios for each.
Link to this question

4.What are generics in C# and what problems do they solve? Provide an example of a generic class or method.

Warm-up

What a strong answer covers

  • Generics allow you to define classes, interfaces, and methods with placeholders for types, resolved at compile time.
  • They solve the problems of type safety (avoiding runtime errors from incorrect casts) and code reusability (writing code once for multiple types).
  • They eliminate boxing/unboxing overhead when working with value types compared to using `object`.
  • Example: `List<T>` or a custom generic `Stack<T>` class, demonstrating how `T` is used.

Where people lose the point

  • Confusing generics with inheritance or polymorphism.
  • Not clearly explaining the performance benefits (avoiding boxing/unboxing).
  • Providing an example that isn't truly generic or doesn't highlight its benefits.
Link to this question

5.Explain LINQ (Language Integrated Query) in C# and demonstrate its use with a simple query on a collection of objects.

Core

What a strong answer covers

  • LINQ provides a uniform way to query data from various sources (collections, databases, XML) directly within C#.
  • It offers type safety and compile-time checking for queries.
  • Demonstrate a query using method syntax (e.g., `Where`, `Select`, `OrderBy`) on a `List<T>` of custom objects.
  • Explain the benefits: readability, reduced boilerplate, strong typing.

Where people lose the point

  • Only showing query syntax without explaining method syntax, or vice-versa.
  • Not explaining the 'integrated' aspect of LINQ.
  • Providing a trivial example that doesn't showcase LINQ's power (e.g., just filtering integers).
Link to this question

6.Describe how `async` and `await` work in C# to enable asynchronous programming. What are the benefits and potential pitfalls?

Core

What a strong answer covers

  • `async` marks a method as asynchronous, allowing `await` within it; `await` pauses execution of the `async` method without blocking the calling thread.
  • Explain that `await` returns control to the caller, and the method resumes when the awaited `Task` completes.
  • Benefits: improved UI responsiveness, better resource utilization (especially for I/O-bound operations), simplified asynchronous code.
  • Pitfalls: `async void` (except for event handlers), deadlocks (e.g., mixing `await` with `.Result` or `.Wait()`), not handling exceptions correctly.

Where people lose the point

  • Incorrectly stating that `await` blocks the thread.
  • Failing to mention `Task` or `Task<TResult>` as the core mechanism.
  • Not discussing the importance of `ConfigureAwait(false)` in library code.
Link to this question

7.What is the `IDisposable` interface and the `using` statement in C#? When and why would you use them?

Core

What a strong answer covers

  • `IDisposable` is an interface for types that hold unmanaged resources (e.g., file handles, network connections) that need explicit cleanup.
  • The `Dispose()` method defined by `IDisposable` is responsible for releasing these resources.
  • The `using` statement provides a convenient syntax to ensure `Dispose()` is called automatically, even if exceptions occur.
  • Use them to prevent resource leaks and ensure deterministic cleanup of unmanaged resources.

Where people lose the point

  • Confusing `IDisposable` with garbage collection (GC handles managed memory, `IDisposable` handles unmanaged).
  • Not explaining that `using` ensures `Dispose()` is called in a `finally` block.
  • Failing to mention the importance of deterministic cleanup.
Link to this question

8.Explain boxing and unboxing in C#. Provide a code example and discuss their performance implications.

Core

What a strong answer covers

  • Boxing: converting a value type to the `object` type or an interface type it implements. This involves allocating memory on the heap and copying the value.
  • Unboxing: converting an `object` type back to a value type. This involves checking the type and copying the value from the heap to the stack.
  • Provide a clear code example demonstrating both boxing and unboxing.
  • Performance implications: both operations incur overhead due to memory allocation, copying, and type checking, which can impact performance in tight loops.

Where people lose the point

  • Incorrectly stating that unboxing doesn't require a type check.
  • Failing to mention the heap allocation for boxing.
  • Not emphasizing the performance cost, especially in high-frequency scenarios.
Link to this question

9.What are delegates in C# and how are they related to events? Provide a simple example of using a delegate.

Core

What a strong answer covers

  • Delegates are type-safe function pointers; they define a signature (return type and parameters) for methods they can point to.
  • They allow methods to be passed as arguments, stored in variables, and invoked later, enabling callback mechanisms.
  • Events in C# are built on delegates, providing a safe way for a class to notify other classes when something interesting happens.
  • Example: Define a delegate, a method matching its signature, and then assign and invoke the method via the delegate.

Where people lose the point

  • Confusing delegates with interfaces or abstract classes.
  • Not explaining that events add a layer of encapsulation around delegates.
  • Providing an example that doesn't clearly show the delegate's role as a function pointer.
Link to this question

10.Explain the concept of static members (fields, methods, classes) in C#. When would you use them, and what are their limitations?

Core

What a strong answer covers

  • Static members belong to the class itself, not to any specific instance of the class. They are accessed directly via the class name.
  • Static fields are shared across all instances; static methods can only access static members.
  • Static classes can only contain static members and cannot be instantiated or inherited.
  • Use cases: utility classes (e.g., `Math`), shared configuration, factory methods. Limitations: no instance state, cannot be overridden, can lead to tight coupling.

Where people lose the point

  • Incorrectly stating that static members are thread-safe by default.
  • Failing to mention that static classes cannot be instantiated or inherited.
  • Not discussing the implications of shared state in static fields.
Link to this question

11.Describe a common deadlock scenario that can occur when mixing `async`/`await` with synchronous blocking calls (e.g., `.Result` or `.Wait()`). How can it be avoided?

Hard

What a strong answer covers

  • Explain the scenario: a UI thread calls an `async` method using `.Result` or `.Wait()`, blocking itself.
  • The `async` method then `awaits` a task. If the `SynchronizationContext` captures the UI thread, it tries to resume the `async` method on that same blocked UI thread.
  • This creates a deadlock: the UI thread is waiting for the `async` method to complete, and the `async` method is waiting for the UI thread to become available to resume.
  • Avoidance: Use `await` all the way down (async-all-the-way), or use `ConfigureAwait(false)` in library code to prevent context capture.

Where people lose the point

  • Not clearly explaining the role of `SynchronizationContext` in the deadlock.
  • Suggesting `Task.Run` as a universal fix without explaining its limitations.
  • Failing to emphasize that `await` should be used consistently.
Link to this question

12.What is Reflection in C#? Provide at least two practical use cases where Reflection would be beneficial.

Hard

What a strong answer covers

  • Reflection is the ability of a program to examine and modify its own structure and behavior at runtime.
  • It allows inspecting metadata (types, members, attributes) and invoking members dynamically.
  • Use case 1: Plugin architectures or extensibility frameworks, where types are loaded and instantiated dynamically based on configuration.
  • Use case 2: Object-Relational Mappers (ORMs) or serialization libraries that map object properties to database columns or JSON fields at runtime.

Where people lose the point

  • Confusing reflection with code generation or dynamic compilation.
  • Not mentioning the performance overhead associated with reflection.
  • Providing trivial or non-practical use cases.
Link to this question

13.Explain how garbage collection works in .NET. What are generations, and how do they optimize the process?

Hard

What a strong answer covers

  • The .NET Garbage Collector (GC) automatically manages memory for managed objects on the heap, reclaiming memory occupied by objects no longer referenced.
  • It's a generational collector: objects are grouped into generations (Gen 0, Gen 1, Gen 2) based on their lifetime.
  • Gen 0 is for short-lived objects, Gen 1 for objects surviving Gen 0 collections, Gen 2 for long-lived objects.
  • Generational collection optimizes by frequently collecting Gen 0 (which is fast) and less frequently collecting older generations, based on the 'infant mortality' hypothesis.

Where people lose the point

  • Confusing GC with `IDisposable` or manual memory management.
  • Incorrectly describing the flow between generations or the purpose of each.
  • Failing to mention that GC is non-deterministic.
Link to this question

14.What are extension methods in C#? Explain their purpose and provide an example. Discuss design considerations when creating them.

Core

What a strong answer covers

  • Extension methods allow you to add new methods to existing types without modifying the original type or creating a derived type.
  • They are static methods defined in a static class, with their first parameter prefixed by `this` keyword.
  • Purpose: enhance existing types (e.g., `string`, `IEnumerable<T>`) with new functionality, improve readability, and promote a fluent API style.
  • Design considerations: use sparingly, avoid name collisions, ensure they add value and don't break encapsulation, consider if a utility class or inheritance is more appropriate.

Where people lose the point

  • Incorrectly stating that extension methods modify the original type.
  • Forgetting the `this` keyword or that they must be in a static class.
  • Not discussing the potential for misuse or over-extension.
Link to this question

15.When should you choose a `struct` over a `class` in C#? What are the trade-offs?

Hard

What a strong answer covers

  • Choose `struct` for small, simple data types that primarily hold values and do not require inheritance (e.g., `Point`, `Color`).
  • Structs are value types, allocated on the stack (or inline in arrays/objects), leading to fewer heap allocations and potentially better performance for small types.
  • Trade-offs: Structs are copied by value, which can be inefficient for large structs. They cannot be null, cannot inherit from other structs/classes (only implement interfaces), and have no default constructor.
  • General guideline: Use `struct` if it's small (under 16 bytes), immutable, and doesn't need reference semantics.

Where people lose the point

  • Suggesting structs for large, complex objects.
  • Failing to mention the immutability aspect or the inability to be null.
  • Not clearly articulating the performance trade-offs (copying vs. heap allocation).
Link to this question
No account needed

Answer one real C# question now

A question a C# panel actually asks, answered out loud, scored on what you said and how you said it. Under two minutes, and nothing to sign up for.

Explain the four pillars of Object-Oriented Programming (OOP) and provide a simple C# example for each.

We never store the audio. Your answer is deleted within 24 hours unless you save the result.

How C# answers get judged

The weights a C# interviewer is holding, whether or not they say so out loud. Round Zero scores your practice answers against exactly these, and quotes your own words back as the evidence for each.

Technical Accuracy

40%

The answer demonstrates a correct and precise understanding of C# syntax, semantics, and framework features. No factual errors or misunderstandings.

Conceptual Depth

30%

The candidate explains not just 'what' but 'why' concepts work the way they do, demonstrating an understanding of underlying principles, trade-offs, and implications.

Problem Solving & Application

20%

The ability to apply C# concepts to practical scenarios, provide relevant examples, and discuss appropriate use cases or design patterns.

Communication Clarity

10%

The explanation is clear, concise, well-structured, and easy to follow. Technical terms are used accurately and effectively.

Related Programming Languages skills

All skills →

Now say them out loud

You have read what strong C# answers contain. The next thing that moves the needle is producing one under time, out loud, and finding out where it falls apart.

  • These questions asked back, with follow-ups
  • Flashcards for the ones you keep missing
  • A scored mock that quotes your own answers

Browse every skill

Practising C#: common questions

What C# interview questions should I practice?
Start with the core areas C# interviewers probe: Explain the four pillars of Object-Oriented Programming (OOP) and provide a simple C# example for each.; What is the fundamental difference between value types and reference types in C#? Provide examples of each and explain their memory allocation.; Compare and contrast interfaces and abstract classes in C#. When would you choose one over the other. This page outlines strong answers and common mistakes, and the scored path drills each one with follow-ups.
Is the C# practice free?
Yes. The C# path runs free inside Round Zero: lessons, practice questions and flashcards. Drills are unlimited on every plan, free included. So is the full scorecard. Free also covers 3 complete scored interviews, no card.
How is this different from a C# question list?
A static list gives you questions with no feedback. Round Zero runs a live scored practice that probes your actual answers, rotates difficulty, and tells you exactly what to fix, grounded in a C# rubric.
How should I prepare for a C# interview?
Learn the concepts, drill the questions until answers come fast, then prove it in a scored mock. Round Zero sequences all three so you know you are ready, not just that you read about C#.
How is a C# answer scored?
C# answers are scored on technical accuracy, conceptual depth, problem solving & application, communication clarity, with evidence quoted from what you actually said, so feedback is specific instead of generic praise.