C# Interview Foundations: Types, LINQ, and Concurrency
SaveA practical C# interview path covering the type system, object-oriented design, generics, collections, LINQ, resource safety, async workflows, cancellation, and .NET memory management.
Course coverage
Tracks, skills, and topics covered by this prep path.
Your progress
Start this path to keep your place across devices.
Course assessment
Full path practice
Test what you learned across every module.
Module 1
- 1
- 2
- 3Optional
Module 2
- 4Optional
- 5Optional
Module 3
- 6Optional
- 7Optional
- 8Optional
Module 4
- 9Optional
Lesson 1 of 9 | C# Type System and OOP
Value Types vs Reference Types: Copying, Boxing, and Equality
Learning goals
By the end of this lesson you should be able to explain copying semantics, identify boxing, and choose the right equality contract without repeating the misleading rule that every value type lives on the stack.
The useful mental model
A value-type variable contains its value directly. Assigning it normally copies that value. A reference-type variable contains a reference to an object; assigning it copies the reference, so both variables can observe the same object.
int first = 10;
int second = first;
second++;
// first is still 10
var alice = new Candidate { Name = "Alice" };
var alias = alice;
alias.Name = "Alicia";
// alice.Name is now "Alicia"
Storage location depends on context. A value-type field can live inside a heap object, and a local may be optimized into a register. Focus on semantics, not a stack-versus-heap slogan.
Boxing and unboxing
Boxing converts a value type to object or an implemented interface and requires an object allocation. Unboxing extracts the original value type and must use the compatible runtime type.
int score = 42; object boxed = score; // boxing allocation int copy = (int)boxed; // unboxing
Generic collections avoid repeated boxing for value types. Prefer List<int> over non-generic collections when values remain integers.
Equality choices
- Value types receive field-based
ValueType.Equalsbehavior unless overridden. - Classes use reference equality by default.
- Records provide value-oriented equality that is useful for immutable data models.
- Implement
IEquatable<T>when a domain type needs an explicit, efficient equality contract.
Interview checkpoints
- Assignment copies a value for structs and a reference for classes.
- Boxing is a conversion plus allocation, not merely a cast.
- Mutable structs are risky because hidden copies make updates surprising.
- Equality and identity are separate design decisions.
A strong answer describes observable semantics first and treats storage as an implementation detail shaped by context and runtime optimization.