Skip to content
Sharp

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.

  • Classes, 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/override gives runtime dispatch. new only *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 cards

    Query 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() returns default.
  • Async / await

    4 Q · 2 cards

    Tasks, continuations, synchronization context, cancellation.

    4 questions with answers →Test this topic →
    Key ideas
    • await on 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 await runs synchronously on the caller's thread.
    • Avoid .Result/.Wait() (deadlocks, thread-pool starvation). Go async all the way and pass CancellationTokens.
    • async void is only for event handlers.
  • Generics

    3 Q · 2 cards

    Type 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 what T can 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 like IEnumerable<T>; in T (contravariant) for consumers like Action<T>.
  • Delegates & events

    3 Q · 2 cards

    Func, 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 event restricts outside code to +=/-=. Only the declaring class can raise it.
    • Lambdas capture variables, not values. A for loop variable is shared across iterations.
  • Collections

    3 Q · 2 cards

    List, 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> and HashSet<T>: O(1) average lookup; keys need consistent Equals/GetHashCode.
    • SortedDictionary: balanced tree, O(log n).
    • Don't modify a List<T> while foreach-ing it. Use ConcurrentDictionary etc. for multi-threaded access.
  • Memory & GC

    3 Q · 2 cards

    Value 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 IDisposable and use using for 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 cards

    Middleware 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.
  • Dependency injection

    4 Q · 2 cards

    Service 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.
  • Exceptions

    3 Q · 2 cards

    try/catch/finally, filters, rethrowing, best practices.

    3 questions with answers →Test this topic →
    Key ideas
    • finally always runs when control leaves the try (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.