📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š .NET Interview Questions

377 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.

  1. How do params work in modern C#, and what changed with C# 13 params collections? Explain params arrays and their hidden allocations, params ReadOnlySpan<T>, params IEnumerable<T> and List<T>, how overload resolution chooses between them, the new BCL overloads in .NET 9, and API design guidance.

    params arrays versus C# 13 params collections, allocations, overload resolution and API design.

    Mid-Level Theory Memory-Oriented C# Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  2. What does readonly mean in each place it can appear in C#? Explain readonly fields, static readonly versus const (and the versioning trap), readonly structs, readonly members, readonly ref returns, how the JIT treats static readonly values, and why readonly does not make an object immutable.

    readonly across fields, structs, members and refs, const versus static readonly, and immutability limits.

    Mid-Level Theory Memory-Oriented C# Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  3. What is a ref struct and when would you write one? Explain the rules (stack-only, no boxing, no class fields, no lambda capture), ref fields (C# 11), C# 13 changes (implementing interfaces, the allows ref struct anti-constraint, use in async and iterator methods), the Dispose pattern for ref structs, and walk through a ValueStringBuilder-style type.

    Writing ref structs: rules, ref fields, C# 13 interface and generic support, and a stack-first builder example.

    Senior Coding Memory-Oriented C# Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  4. How do you use stackalloc safely in modern C#? Explain stackalloc into Span<T>, the unmanaged type requirement, stack size limits and why a stack overflow kills the process, the hybrid stackalloc-or-ArrayPool pattern, why you must not stackalloc in loops, SkipLocalsInit, and how to choose a threshold.

    Safe stackalloc: span usage, size limits, hybrid pooling pattern, loops and SkipLocalsInit.

    Mid-Level Coding Memory-Oriented C# Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  5. When is unsafe code justified in modern C#, and what tools exist beyond raw pointers? Explain unsafe blocks, pointers and fixed (pinning), function pointers, NativeMemory, the System.Runtime.CompilerServices.Unsafe class, MemoryMarshal, what can go wrong (GC holes, buffer overruns, pinning cost), and how to keep unsafe code safe.

    Unsafe C#: pointers, fixed, NativeMemory, the Unsafe class and MemoryMarshal, risks and guidelines.

    Senior Theory Memory-Oriented C# Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  6. A service using ArrayPool<T> intermittently returns corrupted data, and once returned another customer's data in a response. How do you debug and fix ArrayPool misuse? Cover use-after-return, double return, assuming the rented length, not clearing sensitive data, returning foreign arrays, and the tools and test techniques that catch these bugs.

    Debugging ArrayPool<T> misuse: lifetime bugs, length assumptions, clearing, diagnostics and safe patterns.

    Senior Debugging Memory-Oriented C# Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  7. How do MemoryPool<T> and IMemoryOwner<T> work, and when would you use them instead of ArrayPool<T>? Explain renting and disposing owners, why the buffer can be larger than requested, ownership transfer between components, how System.IO.Pipelines uses a memory pool, writing a custom pool or MemoryManager<T> for native or pinned memory, and common mistakes.

    MemoryPool<T> and IMemoryOwner<T>: ownership-based pooling, pipelines and custom memory managers.

    Senior Theory Memory-Oriented C# Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  8. What is the Common Language Runtime (CLR), and which services does it give your .NET application?

    The CLR as the execution engine of .NET: loading, JIT, type safety, GC, exceptions, threading and interop.

    Mid-Level Theory CLR Fundamentals Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  9. What is the Common Type System (CTS), and how does it let different .NET languages share types?

    The CTS rules for value and reference types, members, inheritance and how language keywords map to CTS types.

    Mid-Level Theory CLR Fundamentals Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  10. What is the Common Language Specification (CLS), and when should you mark a library as CLSCompliant?

    CLS rules for cross-language public APIs, the CLSCompliant attribute and the compiler warnings it enables.

    Mid-Level Theory CLR Fundamentals Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  11. What is a .NET assembly, and what does assembly identity (name, version, culture, public key token) mean in modern .NET?

    Assemblies as the unit of deployment and versioning, their contents, identity and how modern .NET treats versions and strong names.

    Mid-Level Theory CLR Fundamentals Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  12. What are metadata and the manifest in a .NET assembly, and how can you read them without loading the assembly?

    Metadata tables and tokens, the assembly manifest, type forwarding, and reading them with System.Reflection.Metadata.

    Senior Theory CLR Fundamentals Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  13. What is IL (Intermediate Language), and how do you read the IL the C# compiler produces?

    CIL as a stack-based instruction set, common opcodes, callvirt, boxing in IL, and tools to inspect it.

    Mid-Level Theory CLR Fundamentals Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  14. How does the JIT compiler work in .NET, and how can you see the machine code it generates?

    Just-in-time compilation per method via stubs, what the JIT produces, and inspecting output with DOTNET_JitDisasm.

    Senior Theory CLR Fundamentals Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  15. How does tiered compilation work in .NET, including Tier 0, Tier 1 and on-stack replacement (OSR)?

    Tiered JIT: quick unoptimised code first, call counting, background Tier 1 recompilation, OSR for loops and the settings that control it.

    Senior Theory CLR Fundamentals Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  16. What is Dynamic PGO in .NET, and how does guarded devirtualisation make interface and virtual calls faster?

    Profile-guided optimisation at run time: instrumentation, guarded devirtualisation, hot/cold layout and how traffic shape affects it.

    Senior Theory CLR Fundamentals Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  17. What is ReadyToRun (R2R), and when should you publish with it?

    ReadyToRun precompilation with crossgen2: startup benefits, size cost, version resilience, composite images and how it interacts with tiering.

    Mid-Level Theory CLR Fundamentals Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  18. What is NativeAOT in .NET, what does it give you and what are its restrictions?

    Native ahead-of-time compilation: startup and memory gains, required trimming, reflection and dynamic code limits, ASP.NET Core support and analysers.

    Senior Theory CLR Fundamentals Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  19. What does single-file publish do in .NET, and what breaks when you switch an app to it?

    PublishSingleFile bundling, framework-dependent versus self-contained, native library extraction, Assembly.Location and IL3000.

    Mid-Level Theory CLR Fundamentals Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  20. How does IL trimming work in .NET, and how do you make an app or library trim-safe?

    ILLink trimming, TrimMode, trim warnings, DynamicallyAccessedMembers and RequiresUnreferencedCode, feature switches and IsTrimmable.

    Senior Theory CLR Fundamentals Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me