0
0
C Sharp (C#)programming~5 mins

Value types vs reference types mental model in C Sharp (C#) - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is a value type in C#?
A value type stores the actual data directly. When you assign it to another variable, a copy of the data is made.
Click to reveal answer
beginner
What is a reference type in C#?
A reference type stores a reference (or address) to the actual data in memory. Assigning it to another variable copies the reference, not the data.
Click to reveal answer
beginner
How does changing a value type variable affect another variable it was assigned to?
It does not affect the other variable because each has its own copy of the data.
Click to reveal answer
beginner
How does changing a reference type variable affect another variable it was assigned to?
Changing the data through one variable affects the other because both variables point to the same data in memory.
Click to reveal answer
beginner
Give an example of a value type and a reference type in C#.
Value type example: int, struct. Reference type example: class, string.
Click to reveal answer
Which of these is a value type in C#?
Aclass
Bstring
Cint
Darray
What happens when you assign one reference type variable to another?
ABoth variables point to the same data
BThe data is deleted
CA copy of the data is made
DThe variables become value types
If you change a value type variable after assigning it to another, what happens to the other variable?
AIt changes too
BIt stays the same
CIt becomes null
DIt throws an error
Which of these is stored on the stack in C#?
AReference types
BNeither
CBoth value and reference types
DValue types
Which keyword defines a value type in C#?
Astruct
Bdelegate
Cinterface
Dclass
Explain the difference between value types and reference types in C# using a real-life analogy.
Think about copying a physical object versus sharing a pointer to it.
You got /5 concepts.
    Describe what happens in memory when you assign one reference type variable to another and then modify the data.
    Focus on shared memory and references.
    You got /4 concepts.