mediumConceptMidSeniorStaff
What is the difference between a value type and a reference type in C#, and what do nullable reference types guarantee?
C# value types store data directly and copy on assignment, while reference types store references to heap objects. Nullable reference types are compile-time flow-analysis warnings, not runtime null guarantees. It also connects structs to the point an interviewer is testing.
5 min readUpdated 2026-08-15
Answer
Short answer
In C#, a value type value is copied when assigned or passed, while a reference type variable copies a reference to the same heap object. Nullable reference types do not change runtime behavior; they add compile-time warnings that help track possible null values.
Was this answer helpful?
Likely follow-ups
- When would you make a type a struct rather than a class, and what would you measure to justify it?
- What does readonly struct change, and what does the in parameter modifier do without it?
- Your API returns a record with a non-nullable string property and a client receives null. How did that happen?
- How does Nullable<T> differ from a nullable reference type in what the compiler emits?
Related questions
- When would you make a type a record, a struct, or a class? What does each choose for you?mediumAlso on structs and value-types4 min
- Memory keeps climbing in a Go service under load. How do you find out why, and what can you actually tune?hardAlso on memory6 min
- How do generators reduce memory use, and when are they the wrong choice?mediumAlso on memory5 min
- A long-running Python service keeps climbing in memory and never comes back down. How do you work out where the memory went?hardAlso on memory5 min