C# and .NET: language, runtime and ASP.NET Core – Server Side interview prep

261 interview-style multiple-choice questions on C# and .NET: language, runtime and ASP.NET Core, organized by topic: concepts, scenarios, code to read and tradeoffs, each with a short explanation. Learn the 107 key terms with the flashcards first, then test yourself.

Take the practice test · Flashcards · All study tools

What it covers

  1. 7.1 C# types, equality and resources
  2. 7.2 Modern C# language features
  3. 7.3 Async/await and tasks
  4. 7.4 LINQ, collections and generics
  5. 7.5 Runtime: GC, JIT, AOT and assemblies
  6. 7.6 Performance and low-allocation code
  7. 7.7 ASP.NET Core pipeline, routing and APIs
  8. 7.8 ASP.NET Core services: HTTP, logging, resilience and security
  9. 7.9 Platform, tooling, testing and deployment

Key terms

7.1 C# types, equality and resources

Value type
A type copied on assignment, such as struct or int
Reference type
A type whose variables hold references to heap objects
record
Type with built-in value equality and with-expressions
Extension method
Static method callable with instance syntax
Value equality
Comparing contents rather than identity
Record struct
Value type with generated equality
Nullable<T>
Wrapper adding "no value" to a value type
Null-forgiving operator
`!` that silences a null warning
readonly struct
Struct whose fields can't change
IAsyncDisposable
Asynchronous cleanup contract
SafeHandle
Managed wrapper for an OS handle
Flags enum
Enum whose values combine as bits
checked context
Arithmetic that throws on overflow

7.2 Modern C# language features

Property pattern
Matching on property values
List pattern
Matching sequence shape
Extension members
C# 14 extension properties and statics
field keyword
Backing field in a property accessor
Collection expression
Bracket syntax for collections
init accessor
Set once during initialization
required member
Property callers must set
Raw string literal
Triple-quoted string without escapes
Static abstract member
Interface member implemented as static
Covariance
Using a more derived type argument
Default interface method
Interface member with a body
Target-typed new
`new()` inferring its type

7.3 Async/await and tasks

async/await
Language support for non-blocking asynchronous code
Task
Represents an asynchronous operation
Deferred execution
LINQ queries run only when enumerated
IQueryable
Query interface translated by a provider, such as to SQL
ValueTask
Allocation-light awaitable for often-sync results
IAsyncEnumerable
Asynchronous stream of items
SemaphoreSlim
Lightweight semaphore with async waits
Channel<T>
In-process async producer/consumer queue
TaskCompletionSource
Manually completed Task
Linked token source
Token canceled when any source cancels
Thread pool starvation
Pool threads blocked, work queues up
PeriodicTimer
Async timer loop
AsyncLocal
Ambient value flowing across awaits

7.4 LINQ, collections and generics

Materialization
Running a query into a list or array
SelectMany
Map and flatten
ToLookup
Key to many values, built eagerly
Chunk
Split a sequence into batches
CountBy
Count items per key
FrozenDictionary
Read-optimized immutable dictionary
Reified generics
Type arguments kept at runtime
Iterator method
Method using yield return

7.5 Runtime: GC, JIT, AOT and assemblies

IL
Intermediate language that .NET compilers produce
JIT
Just-in-time compilation of IL to native code
Garbage collector
Automatic memory manager for unreachable objects
Boxing
Wrapping a value type in a heap object
Large object heap
Heap for objects of 85,000+ bytes
Server GC
Per-core heaps for throughput
Tiered compilation
Quick JIT first, optimize hot code later
Dynamic PGO
Runtime profile-guided optimization
ReadyToRun
Precompiled native code plus IL
AssemblyLoadContext
Isolated, unloadable assembly loading
Trimming
Removing unused code at publish
DATAS
GC heap count adapting to the workload
Pinned object heap
Separate heap for objects that can't move
LibraryImport
Source-generated P/Invoke

7.6 Performance and low-allocation code

ArrayPool
Shared pool of rentable arrays
stackalloc
Stack-allocated buffer
ref struct
Stack-only type
BenchmarkDotNet
.NET micro-benchmark library
SearchValues
Precomputed search set
Devirtualization
Turning virtual calls into direct calls
JSON source generation
Build-time serializers
UTF-8 literal
`"text"u8` byte span
System.IO.Pipelines
Pooled, backpressured stream parsing
InlineArray
Fixed-size inline buffer in a struct

7.7 ASP.NET Core pipeline, routing and APIs

Middleware
Pipeline component that handles HTTP requests
Scoped lifetime
One service instance per request
Kestrel
ASP.NET Core's built-in web server
Options pattern
Binding configuration sections to typed classes
Terminal middleware
Middleware that ends the pipeline
Route constraint
Rule a route segment must meet
Route group
Shared prefix and conventions
Endpoint filter
Minimal API before/after hook
TypedResults
Strongly typed minimal API results
IExceptionHandler
Pluggable exception-to-response handler
Output caching
Server-side response cache with tags
Forwarded headers
Restoring client IP and scheme behind proxies
Render mode
Blazor rendering and interactivity choice

7.8 ASP.NET Core services: HTTP, logging, resilience and security

Typed client
Class wrapping a factory-managed HttpClient
Standard resilience handler
Preset Polly pipeline for HttpClient
ResiliencePipeline
Polly v8 chain of strategies
DelegatingHandler
Outbound HTTP pipeline step
Message template
Log text with named placeholders
LoggerMessage
Source-generated logging methods
ActivitySource
.NET API for creating spans
Aspire
Stack for orchestrating distributed apps
HybridCache
Two-level cache with stampede protection
Data Protection
Key ring for encrypting cookies and tokens
Authorization policy
Named set of access requirements

7.9 Platform, tooling, testing and deployment

LTS
Long-term support release, 3 years
STS
Standard-term support release, 2 years
global.json
Pins the .NET SDK version
Multi-targeting
Building one project for several frameworks
Central Package Management
One file for package versions
Self-contained publish
Output bundles the runtime
Chiseled image
Minimal Ubuntu base without a shell
Source generator
Compile-time code producer
File-based app
Running a single .cs file
IClassFixture
Shared xUnit fixture per class
Microsoft.Testing.Platform
Lightweight .NET test runner
SourceLink
Debugging into a package's source
NuGet audit
Vulnerability warnings during restore

Sample practice questions

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

    1. There's been no difference between them since C# 10 shipped
    2. A struct can declare methods, but a class can only declare fields
    3. A class is a reference type; a struct is a value type copied on assignment
    4. A class is always immutable, while a struct is always mutable

    Answer: C. A class is a reference type; a struct is a value type copied on assignment Use structs for small, immutable values to avoid allocations.

  2. What does pattern matching with a switch expression look like?

    1. `var label = switch (shape) { case Circle c: "r"; case Square s when s.Side > 10: "big"; default: "other"; }`
    2. `var label = shape match { Circle c -> $"r={c.R}", Square { Side > 10 } -> "big", else -> "other" };`
    3. `var label = shape switch { Circle c => $"r={c.R}", Square { Side: > 10 } => "big", _ => "other" };`
    4. `var label = shape switch (Circle c) => $"r={c.R}" | (Square { Side: > 10 }) => "big" | default => "other";`

    Answer: C. `var label = shape switch { Circle c => $"r={c.R}", Square { Side: > 10 } => "big", _ => "other" };` Property and relational patterns make complex conditions concise.

  3. What does `await` do in a C# async method?

    1. It suspends the method without blocking the thread, then resumes
    2. It starts a new dedicated thread for the rest of the method
    3. It blocks the current thread until the awaited task completes
    4. It cancels the task automatically if it takes too long

    Answer: A. It suspends the method without blocking the thread, then resumes The freed thread can serve other work, such as other requests.

  4. When does this LINQ query actually run against the database? ```csharp var q = db.Orders.Where(o => o.Total > 100); var list = await q.ToListAsync(); ```

    1. Never; LINQ queries only ever run in memory, not in databases
    2. Every single time the variable `q` is referenced anywhere in code
    3. Immediately, as soon as the `Where` line has finished running
    4. At `ToListAsync()`; until then `q` is only a query definition

    Answer: D. At `ToListAsync()`; until then `q` is only a query definition This is deferred execution; enumerating twice runs the query twice.

  5. What does the .NET garbage collector do?

    1. Closes and releases idle database connections
    2. Frees memory for objects no longer reachable from live references
    3. Deletes unused temporary files from the application's disk
    4. Frees memory the instant a variable goes out of scope

    Answer: B. Frees memory for objects no longer reachable from live references Unmanaged resources still need `Dispose`.

  6. What does boxing mean in C#?

    1. Wrapping a block of code inside a `try`/`catch` statement
    2. Converting a class into a struct to avoid allocations
    3. Wrapping a value type in a heap object, like `int` to `object`
    4. Compressing a large struct so it takes less memory

    Answer: C. Wrapping a value type in a heap object, like `int` to `object` Boxing allocates and can hurt performance in hot code.

  7. What is middleware in ASP.NET Core?

    1. Code that only runs once, while the application is starting up
    2. Database drivers that Entity Framework uses to reach SQL Server
    3. A separate server process that runs in front of Kestrel
    4. Pipeline components that handle a request and call the next or stop

    Answer: D. Pipeline components that handle a request and call the next or stop Order matters: for example, authentication must come before authorization.

  8. What are the three built-in service lifetimes in ASP.NET Core dependency injection?

    1. Static, dynamic and lazy
    2. Request, session and application
    3. Transient, scoped and singleton
    4. Short, medium and long

    Answer: C. Transient, scoped and singleton Scoped services live for one HTTP request, like an EF Core `DbContext`.

  9. What is the difference between .NET Framework and modern .NET (5 and later)?

    1. Framework is Windows-only and in maintenance; modern .NET is cross-platform
    2. They're the same product, just marketed under different names
    3. Modern .NET only runs on Linux, while .NET Framework runs on Windows
    4. .NET Framework is the newer product, and it's the cross-platform one

    Answer: A. Framework is Windows-only and in maintenance; modern .NET is cross-platform .NET Core was renamed to .NET starting with version 5.

  10. What does this print? ```csharp var a = new Point(1, 2); var b = a; b.X = 10; Console.WriteLine(a.X); // struct Point { public int X; public int Y; public Point(int x, int y) { X = x; Y = y; } } ```

    1. A compile error, because struct fields can't be changed
    2. `10`, because `b` refers to the same object as `a`
    3. `0`, because structs reset on assignment
    4. `1`, because the struct was copied when assigned to `b`

    Answer: D. `1`, because the struct was copied when assigned to `b` If `Point` were a class, it would print `10`.

Practice all 261 questions

More Server Side