C#-Übungen

Immutable Order Record

Records make value-based models concise and safe to copy.

How it works

Update immutable data with a with expression.

The original record is preserved while the copy receives a different status.

Runnable C# example

C#
Run code →
Program.cs
using System;
record Order(int Id, string Status);
class Program
{
    static void Main()
    {
        var pending = new Order(7, "Pending");
        var shipped = pending with { Status = "Shipped" };
        Console.WriteLine($"{pending.Status} -> {shipped.Status}");
    }
}
Expected output
Pending -> Shipped

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.