> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# Property Pattern

The property pattern is a pattern matching construct in C# that enables you to match an expression's properties or fields against nested patterns. It evaluates to `true` if the input expression is non-null and every specified property or field matches its corresponding pattern.

## Syntax

The property pattern is defined using curly braces `{ }` containing a comma-separated list of property names, a colon `:`, and the nested pattern to match against that property.

```csharp theme={"dark"}
{ Property1: <Pattern>, Property2: <Pattern> }
```

It is most frequently combined with a type pattern to ensure the object is of a specific type before evaluating its properties:

```csharp theme={"dark"}
<Type> { Property1: <Pattern> }
```

## Core Mechanics

**Implicit Null Checking**
A property pattern inherently guarantees that the input is not null. If the input expression evaluates to `null`, the pattern immediately returns `false` without throwing a `NullReferenceException`. Consequently, an empty property pattern is commonly used as a concise non-null check.

```csharp theme={"dark"}
// Evaluates to true if obj is not null
bool isNotNull = obj is { };
```

**Constant and Relational Matching**
Properties can be matched against constant values or evaluated using relational patterns (`<`, `>`, `<=`, `>=`).

```csharp theme={"dark"}
// Matches if obj is a Person, Age is 30 or greater, and Status is "Active"
bool match = obj is Person { Age: >= 30, Status: "Active" };
```

**Variable Capture (Declaration Pattern)**
You can extract property values directly into local variables during the match by combining the property pattern with a declaration pattern.

```csharp theme={"dark"}
// If obj is a Person, extracts the Name property into the 'personName' variable
if (obj is Person { Name: string personName })
{
    Console.WriteLine(personName);
}

// Using 'var' for implicit typing during capture
bool match = obj is Person { Age: var extractedAge };
```

**Nested Property Patterns**
Because the right side of the colon accepts any valid C# pattern, property patterns can be nested recursively to evaluate complex object graphs.

```csharp theme={"dark"}
// Matches if the Person's Address property has a City property equal to "Seattle"
bool match = obj is Person { Address: { City: "Seattle" } };
```

**Extended Property Patterns (C# 10+)**
Starting in C# 10, you can reference nested properties directly using dot notation, eliminating the need for nested curly braces. This provides a more concise syntax for deep property evaluation.

```csharp theme={"dark"}
// Functionally identical to the nested example above
bool match = obj is Person { Address.City: "Seattle" };
```

**Logical Combinators**
Property patterns fully support logical combinators (`and`, `or`, `not`) within the nested pattern evaluation.

```csharp theme={"dark"}
// Matches if Age is between 18 and 65, and Name is NOT null
bool match = obj is Person { Age: >= 18 and <= 65, Name: not null };
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
