How to Pass a C# Interview: Top Questions from A to Z

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Introduction

An interview for a C# developer position is not just a syntax check. Employers want to see an understanding of the .NET platform, the principles of the CLR, the ability to write performant code, and knowledge of modern approaches (async, LINQ, DI).

In this article, we will break down top C# questions from A to Z — from basic data types to complex topics like garbage collection and asynchronous programming. Each question is accompanied by a brief answer and a code example so you can feel confident in your interview.



1. Basic Questions: Types, Classes, and Memory



1.1. What is the difference between Value Type and Reference Type?

Value Type (int, struct, enum) are stored on the stack and copied by value. Reference Type (class, string, array) are stored on the heap; the variable contains a reference to the object.

int a = 10;int b = a; // b is a copy, a and b are independent

class MyClass { public int X; }MyClass obj1 = new MyClass { X = 5 };MyClass obj2 = obj1; // obj2 references the same objectobj2.X = 10; // obj1.X will also become 10


1.2. What is Boxing and Unboxing?

Boxing is wrapping a value type into an object (on the heap). Unboxing is the reverse process. Frequent use reduces performance.

int number = 42;object boxed = number;    // Boxingint unboxed = (int)boxed; // Unboxing


1.3. Tell us about the Garbage Collector.

The GC in .NET automatically frees memory from objects that have no references. It works in generations (Gen 0, 1, 2). Large objects (>85 KB) go into the Large Object Heap (LOH).

Tip: Do not call GC.Collect() manually — it disrupts the GC's optimizations.



2. OOP and Design Principles



2.1. Explain the SOLID principles.

  • S — Single Responsibility: a class should have only one reason to change.
  • O — Open/Closed: open for extension, closed for modification.
  • L — Liskov Substitution: subtypes must be substitutable for their base types.
  • I — Interface Segregation: many small interfaces are better than one large one.
  • D — Dependency Inversion: depend on abstractions, not on concrete classes.


2.2. What is Dependency Injection (DI)?

DI is a pattern where dependencies are passed into a class from the outside (via constructor, method, or property). .NET Core has a built-in DI container.

public interface ILogger{    void Log(string message);}

public class ConsoleLogger : ILogger{ public void Log(string message) => Console.WriteLine(message);}

public class OrderService{ private readonly ILogger _logger; public OrderService(ILogger logger) // DI via constructor { _logger = logger; }}


3. LINQ, Exceptions, and Strings



3.1. How does LINQ work? What is deferred execution?

LINQ (Language Integrated Query) allows you to write queries against collections, databases (EF Core), and XML. Deferred execution means the query is executed only when the result is iterated (e.g., via foreach or .ToList()).

var numbers = new List<int> { 1, 2, 3, 4, 5 };var query = numbers.Where(n => n > 2); // query not executednumbers.Add(6); // add after creating the queryforeach (var n in query) // execution happens here    Console.WriteLine(n); // 3, 4, 5, 6


3.2. What is the difference between String and StringBuilder?

String is an immutable type. Each concatenation operation creates a new object. StringBuilder uses a mutable buffer and is efficient for multiple string modifications.

// Bad (many allocations)string s = "";for (int i = 0; i < 1000; i++)    s += i.ToString();

// Good (efficient)StringBuilder sb = new StringBuilder();for (int i = 0; i < 1000; i++) sb.Append(i.ToString());string result = sb.ToString();


4. Async Programming and Multithreading



4.1. How do async and await work?

async marks a method as asynchronous. await suspends the method's execution until the awaited task completes, without blocking the thread. The compiler creates a state machine.

public async Task<string> GetDataAsync(){    using var client = new HttpClient();    string result = await client.GetStringAsync("https://api.example.com");    return result;}


4.2. What is the difference between Task and Thread?

Thread is a low-level operating system concept. Task is a higher-level abstraction representing an asynchronous operation. Tasks use the thread pool and support continuation, cancellation, and returning results.



5. Advanced Questions: Patterns and Performance



5.1. What design patterns are used in C#?

Common patterns: Singleton, Factory, Strategy, Observer, Repository, Unit of Work. In ASP.NET Core, Middleware and DI are actively used.



5.2. How to optimize C# code performance?

  • Avoid boxing/unboxing.
  • Use StringBuilder for string concatenation in loops.
  • Use Span<T> and Memory<T> for working with memory without allocations.
  • Use ValueTask to reduce allocations in high-load scenarios.
  • Properly configure the Garbage Collector (Server/Workstation mode).


Conclusion

We have covered the main topics for a C# interview: from basic types to advanced concepts of asynchronous programming and optimization. Practice writing code, understand the internal workings of .NET, and don't be afraid to ask clarifying questions during the interview.

Good luck with your interview!

Blogs

Book Recommendations