Skip to content

Reference Types

Reference types store a reference to the data on the heap. Assignment copies the reference, not the data.

class Person { public string Name; }
Person p1 = new Person();
p1.Name = "Alice";
Person p2 = p1; // p2 references same object
p2.Name = "Bob";
Console.WriteLine(p1.Name); // Bob
Terminal window
dotnet run
Terminal window
Bob