C# Interview Prep
OOP to ASP.NET Core, the way interviews ask it
Core C# and .NET concepts that come up in developer interviews: object-oriented design, LINQ, async/await, generics, memory, ASP.NET Core and dependency injection.
- Topics
- 10
- Questions
- 33
- Flashcards
- 20
What you'll cover
Open a topic to preview its key ideas, the Learn step of the Sharp method.
Object-oriented programming
4 Q · 2 cardsClasses, inheritance, polymorphism, interfaces and structs.
4 questions with answers →Test this topic →Key ideas
- Encapsulation hides state behind members; inheritance reuses behavior; polymorphism lets a base reference call the most-derived override.
virtual/overridegives runtime dispatch.newonly *hides* a member, so the call depends on the reference type.- Interfaces define contracts (and since C# 8 can carry default implementations). A class has one base class but many interfaces.
structs are value types: copied on assignment, can implement interfaces, can't inherit.
LINQ
4 Q · 2 cardsQuery operators, deferred execution, IEnumerable vs IQueryable.
4 questions with answers →Test this topic →Key ideas
- Most operators (
Where,Select,OrderBy) are deferred: nothing runs until you enumerate. ToList(),ToArray(),Count(),First()force immediate execution.IEnumerable<T>runs delegates in memory;IQueryable<T>builds an expression tree a provider (EF Core) translates to SQL.First()throws on empty sequences;FirstOrDefault()returnsdefault.
- Most operators (
Async / await
4 Q · 2 cardsTasks, continuations, synchronization context, cancellation.
4 questions with answers →Test this topic →Key ideas
awaiton an incomplete task returns to the caller and schedules the rest of the method as a continuation. No thread is blocked while waiting.- Code before the first
awaitruns synchronously on the caller's thread. - Avoid
.Result/.Wait()(deadlocks, thread-pool starvation). Go async all the way and passCancellationTokens. async voidis only for event handlers.
Generics
3 Q · 2 cardsType parameters, constraints, variance.
3 questions with answers →Test this topic →Key ideas
- Generics give compile-time type safety and avoid boxing for value types.
- Constraints (
where T : class,struct,new(), a base type, an interface) limit whatTcan be and unlock members. - Each closed generic type (
List<int>,List<string>) is its own type with its own static fields. - Variance:
out T(covariant) for producers likeIEnumerable<T>;in T(contravariant) for consumers likeAction<T>.
Delegates & events
3 Q · 2 cardsFunc, Action, multicast delegates, events, closures.
3 questions with answers →Test this topic →Key ideas
- A delegate is a type-safe reference to a method.
Func<..., TResult>returns a value;Action<...>doesn't;Predicate<T>returns bool. - Delegates are multicast:
+=adds to the invocation list. - An
eventrestricts outside code to+=/-=. Only the declaring class can raise it. - Lambdas capture variables, not values. A
forloop variable is shared across iterations.
- A delegate is a type-safe reference to a method.
Collections
3 Q · 2 cardsList, Dictionary, HashSet, concurrent collections, complexity.
3 questions with answers →Test this topic →Key ideas
List<T>: dynamic array. O(1) index and amortized O(1)Add, O(n)Contains/insert.Dictionary<TKey,TValue>andHashSet<T>: O(1) average lookup; keys need consistentEquals/GetHashCode.SortedDictionary: balanced tree, O(log n).- Don't modify a
List<T>whileforeach-ing it. UseConcurrentDictionaryetc. for multi-threaded access.
Memory & GC
3 Q · 2 cardsValue vs reference types, garbage collection, IDisposable.
3 questions with answers →Test this topic →Key ideas
- Reference-type instances live on the managed heap; value types live wherever they're declared (a local on the stack, a field inside its containing object).
- The GC is generational (Gen 0/1/2) and compacting; objects of 85,000+ bytes go to the Large Object Heap.
- The GC reclaims memory, not unmanaged resources. Implement
IDisposableand useusingfor files, sockets and DB connections. - Boxing copies a value type into a heap object; avoid it in hot paths.
ASP.NET Core basics
2 Q · 2 cardsMiddleware pipeline, routing, controllers, model binding.
2 questions with answers →Test this topic →Key ideas
- A request flows through a middleware pipeline in the order you register it; each component can short-circuit or call
next. - Typical order: exception handling → HTTPS redirection → static files → routing → CORS → authentication → authorization → endpoints.
[ApiController]enables automatic 400 responses on invalid models and binding-source inference.- Model binding maps route, query, header and body data to action parameters.
- A request flows through a middleware pipeline in the order you register it; each component can short-circuit or call
Dependency injection
4 Q · 2 cardsService lifetimes, constructor injection, captive dependencies.
4 questions with answers →Test this topic →Key ideas
- Register services on
builder.Services; ask for them through constructor injection. - Lifetimes: Transient (new every resolve), Scoped (one per request/scope), Singleton (one for the app).
- A longer-lived service must not hold a shorter-lived one (captive dependency), e.g. a singleton holding a scoped
DbContext. - Singletons that need scoped services should create a scope with
IServiceScopeFactory.
- Register services on
Exceptions
3 Q · 2 cardstry/catch/finally, filters, rethrowing, best practices.
3 questions with answers →Test this topic →Key ideas
finallyalways runs when control leaves thetry(return, exception or normal exit).- Use
throw;to rethrow and keep the original stack trace;throw ex;resets it. - Exception filters (
catch (X e) when (...)) run *before* the stack unwinds. - Catch what you can handle, as specifically as possible; don't use exceptions for normal control flow.
Question formats
Practice the formats you'll actually see. Code examples included.
- Multiple choice · 11
- Fill in the blank · 3
- Select all that apply · 4
- What does this code output? · 7
- Drop-down cloze · 1
- Ordering · 2
- Matrix / grid · 1
- Interview answer · 3
- Highlight text · 1
Start C# Interview Prep
Create a free account to save progress, track weak topics and keep your streak.