menu_book Course Curriculum (C#) expand_more
Property and Relational Patterns
Learn Property and Relational Patterns in C# through a focused explanation, a dedicated topic-specific example, an engineering boundary, and a mastery check.
Property and Relational Patterns is a focused C# lesson inside Control Flow and Pattern Matching. It teaches the API contract behind Property and Relational Patterns, with explicit data flow and error boundaries.
Read the example from the construct outward: identify the exact syntax or API named by the lesson, trace the values that enter it, and predict the result before running the code. The example is intentionally different from neighboring lessons so the behavior of Property and Relational Patterns remains visible instead of being hidden inside a generic demo.
Topic-specific example
record Order(decimal Total, string Status);
static string Classify(Order order) => order switch
{
{ Status: "paid", Total: >= 1000m } => "priority",
{ Status: "paid", Total: > 0m } => "standard",
{ Status: "cancelled" } => "closed",
_ => "review"
};
Console.WriteLine(Classify(new Order(1200m, "paid")));
For Property and Relational Patterns, handle partial data, malformed input, unavailable resources, and cleanup; successful I/O is never the only path.