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
- 7.1 C# types, equality and resources
- 7.2 Modern C# language features
- 7.3 Async/await and tasks
- 7.4 LINQ, collections and generics
- 7.5 Runtime: GC, JIT, AOT and assemblies
- 7.6 Performance and low-allocation code
- 7.7 ASP.NET Core pipeline, routing and APIs
- 7.8 ASP.NET Core services: HTTP, logging, resilience and security
- 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
What is the difference between a `class` and a `struct` in C#?
- There's been no difference between them since C# 10 shipped
- A struct can declare methods, but a class can only declare fields
- A class is a reference type; a struct is a value type copied on assignment
- 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.
What does pattern matching with a switch expression look like?
- `var label = switch (shape) { case Circle c: "r"; case Square s when s.Side > 10: "big"; default: "other"; }`
- `var label = shape match { Circle c -> $"r={c.R}", Square { Side > 10 } -> "big", else -> "other" };`
- `var label = shape switch { Circle c => $"r={c.R}", Square { Side: > 10 } => "big", _ => "other" };`
- `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.
What does `await` do in a C# async method?
- It suspends the method without blocking the thread, then resumes
- It starts a new dedicated thread for the rest of the method
- It blocks the current thread until the awaited task completes
- 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.
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(); ```
- Never; LINQ queries only ever run in memory, not in databases
- Every single time the variable `q` is referenced anywhere in code
- Immediately, as soon as the `Where` line has finished running
- 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.
What does the .NET garbage collector do?
- Closes and releases idle database connections
- Frees memory for objects no longer reachable from live references
- Deletes unused temporary files from the application's disk
- 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`.
What does boxing mean in C#?
- Wrapping a block of code inside a `try`/`catch` statement
- Converting a class into a struct to avoid allocations
- Wrapping a value type in a heap object, like `int` to `object`
- 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.
What is middleware in ASP.NET Core?
- Code that only runs once, while the application is starting up
- Database drivers that Entity Framework uses to reach SQL Server
- A separate server process that runs in front of Kestrel
- 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.
What are the three built-in service lifetimes in ASP.NET Core dependency injection?
- Static, dynamic and lazy
- Request, session and application
- Transient, scoped and singleton
- Short, medium and long
Answer: C. Transient, scoped and singleton Scoped services live for one HTTP request, like an EF Core `DbContext`.
What is the difference between .NET Framework and modern .NET (5 and later)?
- Framework is Windows-only and in maintenance; modern .NET is cross-platform
- They're the same product, just marketed under different names
- Modern .NET only runs on Linux, while .NET Framework runs on Windows
- .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.
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; } } ```
- A compile error, because struct fields can't be changed
- `10`, because `b` refers to the same object as `a`
- `0`, because structs reset on assignment
- `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`.
More Server Side
- HTTP fundamentals
- REST API design
- GraphQL
- gRPC & real-time APIs
- OAuth 2.0, OIDC & JWT
- Sessions, cookies & web app security
- Java & Spring Boot
- Node.js & Express
- Python, Django & FastAPI
- Go (Golang)
- Concurrency & multithreading
- OOP & SOLID
- Design patterns
- Dependency injection
- Logging & observability
- Data structures
- Algorithms & Big-O
- Linux & shell scripting