Interview Question

Value types vs reference types?

Value assignment copies a value; reference assignment copies an object reference.

💡 Concept ✅ Quick Revision 🔷 C#

Answer

A value-type variable contains its value, while a reference-type variable contains a reference to an object. • Assigning a value type normally copies its value. • Assigning a reference type copies the reference, so both variables can identify the same object. • Storage location is an implementation detail; value types are not simply “stack types.”

💡 C# Example

int first = 10; int second = first; second = 20; var listA = new List<int> { 1 }; var listB = listA; listB.Add(2);

⚡ Quick Revision

Value assignment copies a value; reference assignment copies an object reference.