Records and Value Equality
Records are ideal for data-centric models where equality should depend on values.
How it works
Represent immutable data with concise record types.
The with expression creates a copy with one changed property, leaving the original record unchanged.
Runnable C# example
Program.cs
using System;
record User(string Name, string Role);
class Program
{
static void Main()
{
var original = new User("Ada", "Developer");
var promoted = original with { Role = "Lead" };
Console.WriteLine(promoted);
}
}
User { Name = Ada, Role = Lead }Practice with the debugger
Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.