.NET Developer Interview Question

What is the difference between a value type and a reference type in C#?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

A value type, such as an int or a struct, holds its data directly, and assignment copies the whole value. A reference type, such as a class, holds a reference to an object on the heap, so assignment copies the reference and both variables see the same object. Value types are not always on the stack; they live wherever their container lives. Boxing a value type into an object allocates on the heap, which costs performance.

Why interviewers ask this

This is a fundamentals check with real consequences for correctness and performance. The interviewer wants copy semantics explained clearly, the common myth that value types always live on the stack corrected, and an understanding of boxing. Being able to say when you would choose a struct, and why mutable structs cause confusing bugs, shows you go beyond the textbook definition. Records are a natural follow up.

How to structure your answer

  • Define both by what a variable actually holds.
  • Explain assignment and parameter passing.
  • Correct the stack versus heap myth and explain boxing.
  • Say when you would choose a struct and when you would not.

Example answer

Spoken example, first person

The cleanest way to put it is what the variable holds. A value type variable holds the data itself, so when I assign one int or struct to another, I get an independent copy, and changing one does not affect the other. A reference type variable holds a reference to an object, so assigning it copies the reference and both variables point at the same object. Passing to a method follows the same rules unless I use ref. People often say value types live on the stack, but that is only true for locals; a struct field inside a class lives on the heap with that object. Boxing is the cost to watch. Putting a value type into an object or an interface variable allocates a copy on the heap, and in a hot loop that creates real garbage collector pressure. I choose a struct for small, immutable values that behave like a single value, such as a coordinate or a money amount. I avoid mutable structs, because calling a method that changes a struct you got from a list or a property only changes a copy. For most data I use a class or a record.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • What is the difference between a record class and a record struct?
  • When does boxing happen without you noticing?
  • What does marking a struct as readonly give you?

Related .net developer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot