Skip to content

Commit e522f15

Browse files
Update patterns.md with empty property pattern details
Clarify the behavior of the empty property pattern in C#.
1 parent df490d0 commit e522f15

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

docs/csharp/language-reference/operators/patterns.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ You can also add a run-time type check and a variable declaration to a property
182182

183183
:::code language="csharp" source="snippets/patterns/PropertyPattern.cs" id="WithTypeCheck":::
184184

185+
This specifially means that the *empty* property pattern `is { }` matches everything non-null, and can be used instead of the `is not null` to create a variable: `somethingPossiblyNull is { } somethingDefinitelyNotNull`.
186+
185187
A property pattern is a recursive pattern. You can use any pattern as a nested pattern. Use a property pattern to match parts of data against nested patterns, as the following example shows:
186188

187189
:::code language="csharp" source="snippets/patterns/PropertyPattern.cs" id="RecursivePropertyPattern":::

0 commit comments

Comments
 (0)