PrepPilotPractise free

Core C# interview questions

Types, LINQ, async/await, generics, records, nullability

17 questions · C# 12 · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

What is the difference between a struct and a class in C#?

A struct is a value type, meaning its data is stored directly and copied when assigned. A class is a reference type, so its data is stored on the heap and assignments copy the reference. Structs are best for small, immutable data, while classes are used for complex objects.

What does 'boxing' mean in C#?

Boxing is the process of converting a value type, like an int, into a reference type, such as object. This happens when you assign a value type to a variable of type object or pass it as a parameter expecting an object.

How do you define a generic method with a constraint?

You add a where clause to the method signature. For example, public void DoSomething<T>() where T : new() means T must have a parameterless constructor.

What is deferred execution in LINQ?

Deferred execution means that a LINQ query is not executed when it's defined, but only when you enumerate it, such as with a foreach loop or calling ToList().

Intermediate questions

Explain the difference between IEnumerable<T> and IQueryable<T>.

IEnumerable<T> is used for in-memory collections and executes LINQ queries locally. IQueryable<T> is used for remote data sources like databases, and LINQ queries are translated, often to SQL, and executed remotely.

How does async/await improve asynchronous programming in C#?

Async/await allows you to write asynchronous code in a way that looks synchronous, making it easier to read and maintain. It handles continuations automatically, reducing boilerplate and minimizing errors compared to manual callbacks.

When should you use ValueTask instead of Task?

Use ValueTask when the operation often completes synchronously, such as returning a cached value, to avoid allocating a new Task object. For most async APIs, Task is preferred for simplicity unless performance profiling shows a benefit.

What is the purpose of ConfigureAwait(false)?

ConfigureAwait(false) tells the awaiter not to capture the current synchronization context, which helps avoid deadlocks in UI or ASP.NET code and can improve performance in library code.

How do you declare and use an event in C#?

You declare an event using the event keyword and a delegate type. For example, public event Action OnChanged; and then you can subscribe with OnChanged += Handler; and raise it with OnChanged?.Invoke();.

What are nullable reference types and how do they help?

Nullable reference types let you annotate references as nullable (string?) or non-nullable (string). The compiler warns you about possible null dereferences, helping you write safer code and avoid runtime errors.

How do you ensure a resource is disposed of properly in C#?

I use the using statement or declaration, which automatically calls Dispose() on objects implementing IDisposable when the scope ends, even if an exception occurs.

What is pattern matching in modern C#?

Pattern matching lets you check types and extract values concisely. For example, if (obj is Person p && p.Name == "Alice") allows you to both check the type and use the property in one statement.

Senior questions

Describe a scenario where deferred execution in LINQ could cause a bug.

See the answer in the app, free

How can deadlocks occur with async/await in UI or ASP.NET code?

See the answer in the app, free

How would you design a generic repository pattern using constraints?

See the answer in the app, free

How do you handle exceptions in async methods?

See the answer in the app, free

How would you use modern C# features to simplify a class with multiple constructors and property initializations?

See the answer in the app, free

More .NET topics