Object-Oriented C# · Lesson 3

Structs

Assigning a struct copies its fields.

How it works

left is a Purse whose Amount is 10. right = left copies those fields into a second value. Setting right.Amount to 4 writes only into that copy. left stays 10, so the program prints 10 and then 4.

A working example

var left = new Purse(10);
var right = left;
right.Amount = 4;
Console.WriteLine(left.Amount);
Console.WriteLine(right.Amount);

struct Purse
{
    public int Amount;
    public Purse(int amount) { Amount = amount; }
}

Try this
A struct assignment copies the fields.