Value Types and Reference Types in C#
Talk it through out loud with your AI coach.
The problem
- easy
In C#, you change a property on a copy of a struct and the original stays the same, but you do the same with a copy of a class instance and the original changes too. Explain the difference between value types and reference types, and when you'd choose a struct.
What a strong answer covers
- What gets copied on assignment for each kind of type.
- Why the two examples behave differently.
- Where values really live in memory, beyond the usual simplification.
- What makes data a good fit for a struct, and a hidden cost to watch for.
Common mistake: Saying structs always live on the stack and classes on the heap, as if that rule were the defining difference.
Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.
Practise it out loud