C# Fundamentals & Modern Language Features Interview Questions (.NET)
10 C# Fundamentals & Modern Language Features questions from the .NET track. Read each short answer here, then open a question for the full explanation, examples, common mistakes, and sources.
- Junior
What is the basic difference between Value Types and Reference Types in C#, and how are they stored in memory?
Value Types inherit from System.ValueType and store their values directly (usually on the Stack or inside their containing object), while Reference Types inherit from System.Object and store references on the Stack that point to data in the Managed Heap.
Read the full explanation - Mid-level
What are Boxing and Unboxing in C#, and why should they be avoided in high-volume code paths?
Boxing converts a Value Type into an object on the Heap with additional memory allocation, while Unboxing extracts the original value; repeated use burdens the Garbage Collector and slows performance.
Read the full explanation - Junior
How do Record and Class differ in modern C#, and when should you prefer Records?
Records are designed for immutable value objects (Immutability), provide automatic value-based equality, and support non-destructive copying with the with expression.
Read the full explanation - Junior
How do Nullable Reference Types work in C#, and what is the role of Static Flow Analysis?
They distinguish references that allow null (such as string?) from those that do not (string); the compiler uses static analysis to warn before a NullReferenceException occurs at runtime.
Read the full explanation - Mid-level
How have Pattern Matching and switch expressions developed in modern C#?
They now support Property Patterns, Positional Patterns, Relational Patterns, and List Patterns for expressing complex conditions clearly and safely.
Read the full explanation - Junior
How do Delegate, Action, and Func differ, and how does the event keyword protect encapsulation?
A Delegate is a type-safe function pointer; Func returns a value and Action returns nothing. The event keyword prevents external subscribers from invoking the event or clearing its listener list; they can only use += and -=.
Read the full explanation - Senior
What are Span<T> and ReadOnlySpan<T>, and how do they process data without Heap allocation (Zero-Allocation)?
They are ref struct types that represent a contiguous window over memory (Stack, Heap, or Unmanaged Memory) and allow slicing and processing without copying data or allocating new arrays.
Read the full explanation - Mid-level
How do you implement the IDisposable Pattern, and how do Managed and Unmanaged resources differ?
The CLR manages Managed resources automatically, while Unmanaged resources (such as operating system file handles and network sockets) require explicit release through IDisposable and Dispose().
Read the full explanation - Senior
What is Variance in C#, and how do Covariance (out) and Contravariance (in) differ?
Covariance (out) allows a more specific type to be used as an output (Assignment to base), while Contravariance (in) allows a more general type to be used as an input.
Read the full explanation - Senior
What are C# Source Generators, and how do they improve on runtime Reflection?
They are a Roslyn compiler feature that inspects code and generates real C# files during compilation, providing high performance and compile-time type checks without Reflection overhead.
Read the full explanation