Skip to content
TryHired.
Interview prep · Technical · checked against the official docs

C# interview questions: answers checked against the docs

Core C# and .NET questions for back-end, full-stack and game developers, answered in plain words and checked against Microsoft's documentation.

Updated Nov 15, 2026 · Facts checked against the official documentation · questions: TryHired
Quick answer

C# interviews cover value versus reference types, boxing, equality and records, strings, abstract classes versus interfaces, ref, out and in, async and await, LINQ and deferred execution, garbage collection and IDisposable, nullable reference types, delegates and events, generic constraints and dependency injection lifetimes. Below are 14 questions; each answer lists the Microsoft Learn pages it was checked against.

Basic

Basic C# interview questions

Advice

Basic1. What is the difference between value types and reference types?

A value-type variable (int, double, bool, a struct, an enum) holds the value itself, so assigning it copies the data. A reference-type variable (a class, string, array, delegate) holds a reference to an object, so assigning it copies the reference and both variables then point to the same object. That is why changing a copied struct leaves the original alone, while changing an object through a second variable is visible through the first.

C# snippet · illustrative, not run on this page
struct PointS { public int X; }
class PointC { public int X; }

var s1 = new PointS { X = 1 }; var s2 = s1; s2.X = 99;   // s2 is a copy: s1 is unchanged
var c1 = new PointC { X = 1 }; var c2 = c1; c2.X = 99;   // c2 is the same object as c1

Checked against: Microsoft Learn: C# reference types, Microsoft Learn: C# value types

Basic2. What are boxing and unboxing?

Boxing converts a value type to object (or to an interface it implements) by copying it into a new object on the managed heap; unboxing copies it back out with an explicit cast. Each boxing allocates, so it matters in hot loops: that is one reason generic collections such as List<int> replaced the old non-generic ArrayList.

C# snippet · illustrative, not run on this page
int n = 42;
object boxed = n;        // boxing: copies n into a heap object
int back = (int)boxed;   // unboxing: explicit cast copies it out

Checked against: Microsoft Learn: boxing and unboxing

Basic3. What is the difference between == and Equals, and how do records compare?

For classes, == and Equals default to reference equality: two variables are equal only if they point to the same object. Structs compare their values with Equals. Records are built for data: the compiler generates value-based equality, so two record instances with the same property values are equal, and with expressions make modified copies. string is a class but overrides equality to compare text.

C# snippet · illustrative, not run on this page
public record Job(string Title, string City);

var a = new Job("Data Analyst", "Austin");
var b = new Job("Data Analyst", "Austin");
// a == b compares the property values
var c = a with { City = "Denver" };   // nondestructive copy

Checked against: Microsoft Learn: equality comparisons, Microsoft Learn: C# records

Basic4. Why are strings immutable, and when do you use StringBuilder?

A string cannot change after it is created; methods that seem to modify one, such as Replace or concatenation, return a new string. Building a long string in a loop with + therefore creates many intermediate strings. StringBuilder keeps one growable buffer, so it suits repeated appends; for a few concatenations, plain strings or interpolation are fine.

Checked against: Microsoft Learn: strings

Basic5. What is the difference between an abstract class and an interface?

An abstract class is a base class that cannot be instantiated: it can hold state, constructors and implemented members alongside abstract ones, and a class can inherit only one. An interface is a contract that any class, struct or record can implement, and a type can implement several. Since C# 8 interfaces can include default implementations, but they still cannot hold instance state. Use an abstract class for shared implementation in a family of types, an interface for a capability.

Checked against: Microsoft Learn: abstract, Microsoft Learn: interface

Intermediate

Intermediate C# interview questions

Advice

Intermediate6. What do ref, out and in do?

All three pass an argument by reference instead of copying it. ref: the caller must initialize the variable, and the method may change it. out: the caller need not initialize it, and the method must assign it, which is the pattern behind TryParse. in: passes by reference for efficiency (often large structs) but the method cannot modify it.

C# snippet · illustrative, not run on this page
if (int.TryParse("123", out int value))
{
    // value holds the parsed number
}

void AddTax(ref decimal price) => price *= 1.2m;

Checked against: Microsoft Learn: method parameters

Intermediate7. How do async and await work, and what is the difference between a Task and a thread?

await starts or waits for an asynchronous operation without blocking the thread: the method returns to its caller, and the rest of it runs when the task completes. A Task represents an operation and its result; it is not a thread. I/O-bound tasks need no thread while they wait, and CPU-bound work started with Task.Run runs on thread-pool threads. Avoid .Result and .Wait() in async code, because blocking can deadlock and wastes threads.

C# snippet · illustrative, not run on this page
public async Task<string> GetProfileAsync(HttpClient http, int id)
{
    var response = await http.GetAsync($"/users/{id}");   // no thread is blocked here
    response.EnsureSuccessStatusCode();
    return await response.Content.ReadAsStringAsync();
}

Checked against: Microsoft Learn: async and await, Microsoft Learn: task-based asynchronous programming

Intermediate8. What is LINQ, and what is deferred execution?

LINQ is query syntax and methods (Where, Select, OrderBy, GroupBy) built into C# for collections, databases and other sources. Operators such as Where, Select and OrderBy are deferred: the query does nothing when declared and runs when you enumerate it, so it sees the data as it is at that moment and runs again each time you enumerate. Call ToList or ToArray to run it once and keep the results.

C# snippet · illustrative, not run on this page
var jobs = new List<string> { "Analyst", "Engineer" };
var query = jobs.Where(j => j.StartsWith("A"));   // not run yet
jobs.Add("Architect");
foreach (var j in query) Console.WriteLine(j);     // enumerating runs the query now, against the current list
var snapshot = query.ToList();                       // runs now, results cached

Checked against: Microsoft Learn: introduction to LINQ queries, Microsoft Learn: LINQ

Intermediate9. How does garbage collection work in .NET?

The garbage collector manages memory for you: it allocates objects on the managed heap and reclaims ones that are no longer reachable. The heap is split into generations 0, 1 and 2; new objects start in generation 0, which is collected often because short-lived objects are common, and survivors are promoted. The GC frees memory, not other resources such as file handles or connections: those need Dispose.

Checked against: Microsoft Learn: garbage collection

Intermediate10. What is IDisposable, and what does using do?

IDisposable.Dispose releases resources the garbage collector does not manage, such as file handles, sockets and database connections, at a predictable time. A using statement or declaration calls Dispose automatically when the scope ends, even if an exception is thrown.

C# snippet · illustrative, not run on this page
using var stream = File.OpenRead("report.csv");
using var reader = new StreamReader(stream);
string header = reader.ReadLine();
// both are disposed at the end of the enclosing scope

Checked against: Microsoft Learn: implement a Dispose method

Advanced

Advanced C# interview questions

Advice

Advanced11. What are nullable reference types?

With the nullable context enabled, string means a reference that should not be null and string? means one that may be; the compiler warns when you might dereference null or assign null to a non-nullable variable. It is a compile-time analysis: it changes no runtime behavior, so validate input at boundaries anyway.

C# snippet · illustrative, not run on this page
#nullable enable
string name = "Ava";
string? nickname = null;
int length = nickname.Length;        // the compiler flags this line: nickname may be null
int safe = nickname?.Length ?? 0;

Checked against: Microsoft Learn: nullable reference types

Advanced12. What are delegates and events?

A delegate is a type-safe reference to a method with a given signature; Func and Action are the built-in generic delegates, and lambdas convert to them. An event is a delegate field with restricted access: other classes can subscribe and unsubscribe with += and -=, but only the owning class can raise it. Unsubscribe handlers from long-lived publishers, or they keep subscribers alive.

C# snippet · illustrative, not run on this page
public class Downloader
{
    public event EventHandler<int>? ProgressChanged;
    protected void Report(int percent) => ProgressChanged?.Invoke(this, percent);
}

Func<int, int, int> add = (a, b) => a + b;

Checked against: Microsoft Learn: delegates, Microsoft Learn: events

Advanced13. What are generic constraints?

A where clause limits which types a generic parameter accepts, so the code can rely on what those types offer: where T : class, where T : struct, where T : new() for a parameterless constructor, or where T : ISomething to call interface members. Constraints turn would-be runtime failures into compile-time errors.

C# snippet · illustrative, not run on this page
public static T MaxBy<T>(IEnumerable<T> items) where T : IComparable<T>
{
    T best = items.First();
    foreach (var item in items)
        if (item.CompareTo(best) > 0) best = item;
    return best;
}

Checked against: Microsoft Learn: generic constraints

Advanced14. What are the dependency injection lifetimes in .NET, and what is a captive dependency?

Services registered with AddTransient get a new instance each time they are requested, AddScoped one per scope (one per HTTP request in ASP.NET Core), and AddSingleton one for the app's lifetime. A captive dependency is a shorter-lived service held by a longer-lived one, typically a scoped DbContext injected into a singleton, so it outlives its scope; the default container checks for this in development.

C# snippet · illustrative, not run on this page
builder.Services.AddSingleton<IClock, SystemClock>();
builder.Services.AddScoped<IOrderRepository, OrderRepository>();
builder.Services.AddTransient<IEmailFormatter, EmailFormatter>();

Checked against: Microsoft Learn: .NET dependency injection

Practice

How to practice with this page

Advice
  • Explain what happens in memory for the value and reference type questions.
  • Write a small async method and explain where it waits and which thread continues.
  • Rewrite a loop as a LINQ query and say when it runs.
  • For web roles, add ASP.NET Core middleware, routing and Entity Framework Core.
Next

Related interview prep and tools

Disclosure: TryHired makes HIRED, a paid job-search program, so we have a conflict of interest when we mention it. This question bank is free, with no TryHired signup.

FAQ

Questions people ask

What C# topics come up often in interviews?
Value versus reference types, classes, structs and records, interfaces versus abstract classes, async and await, LINQ and deferred execution, collections and generics, exceptions, memory and IDisposable, and for web roles, ASP.NET Core basics such as dependency injection and middleware.
Is C# the same as .NET?
No. C# is a programming language; .NET is the runtime and libraries it usually runs on (along with F# and Visual Basic). Interviews for .NET roles mix both: language questions like the ones here and platform questions about the runtime, ASP.NET Core and Entity Framework Core.
Were these code examples run?
No. The build machine has no .NET SDK, so the snippets are illustrations and no output is shown. The comments describe behavior documented by Microsoft; paste the snippets into a project or an online editor to try them.
Method

How this page is built

TryHired wrote these questions and answers. Statements about the technology were checked against the official documentation pages listed below, saved when the page was built (2026-11-15). The code snippets are short illustrations and were not run on this page. The question list is general practice: it does not predict what a particular employer will ask.

What this page can't tell you
  • Interviewers ask different questions for different roles and levels.
  • Answers are short explanations, not complete references.
  • No .NET SDK was available on the build machine, so no C# code was compiled or run on this page; check snippets against your C# and .NET version, because features differ between versions.
Sources
  1. Microsoft Learn: abstract (read 2026-11-15)
  2. Microsoft Learn: async and await (read 2026-11-15)
  3. Microsoft Learn: boxing and unboxing (read 2026-11-15)
  4. Microsoft Learn: introduction to LINQ queries (read 2026-11-15)
  5. Microsoft Learn: delegates (read 2026-11-15)
  6. Microsoft Learn: .NET dependency injection (read 2026-11-15)
  7. Microsoft Learn: implement a Dispose method (read 2026-11-15)
  8. Microsoft Learn: equality comparisons (read 2026-11-15)
  9. Microsoft Learn: events (read 2026-11-15)
  10. Microsoft Learn: garbage collection (read 2026-11-15)
  11. Microsoft Learn: generic constraints (read 2026-11-15)
  12. Microsoft Learn: interface (read 2026-11-15)
  13. Microsoft Learn: LINQ (read 2026-11-15)
  14. Microsoft Learn: nullable reference types (read 2026-11-15)
  15. Microsoft Learn: C# records (read 2026-11-15)
  16. Microsoft Learn: method parameters (read 2026-11-15)
  17. Microsoft Learn: C# reference types (read 2026-11-15)
  18. Microsoft Learn: strings (read 2026-11-15)
  19. Microsoft Learn: task-based asynchronous programming (read 2026-11-15)
  20. Microsoft Learn: C# value types (read 2026-11-15)