intermediate · 27 minute study
Copying a value and copying a reference are different
Understand why one assignment leaves the original untouched while another changes an object visible through several variables.
Useful preparation · 1 prerequisite
Use this as a map, not a lock. If these ideas are familiar, continue.
- Methods make input, output and responsibility visible — Extract a rule into a method you can call, test and reason about without duplicating it across screens.
First, build a mental model
A struct variable contains a value whose fields are copied on ordinary assignment. A class variable contains a reference; copying that reference gives another route to the same object.
- Value versus reference describes copy and identity semantics. It is not a reliable shortcut for declaring that everything always lives on a particular memory region.
- Changing a copied struct's numeric field does not change the original struct.
- Changing a class instance through one copied reference is visible through the other reference.
- A struct containing a List still contains a reference to that list. Copying the struct does not recursively clone its referenced objects.
var point = new Point { X = 1 };
var pointCopy = point;
pointCopy.X = 9;
var player = new Player { Score = 1 };
var alias = player;
alias.Score = 9;
Console.WriteLine(point.X);
Console.WriteLine(player.Score);
struct Point { public int X; }
sealed class Player { public int Score { get; set; } }- Struct assignment
pointCopy starts with its own copied X value.
- Reference assignment
player and alias point to the same Player object.
- Mutation
The original point stays at 1; the shared Player now has Score 9.
Production thinking
Take this beyond the example.
Prefer small immutable value types for values and explicit identity for entities. Be cautious with mutable structs, shared collections and accidental copies in stateful code.
Sources and further reading
Your evidence
unseen is a local learning signal, not a credential or proof of production competence.
Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.
Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.
Next lesson · A class can protect a rule, not just hold fields →