Skip to content

Commit

Permalink
Make it more clear that a positional pattern relies on Deconstruct (d…
Browse files Browse the repository at this point in the history
…otnet#42514)

* Make it more clear that a positional pattern relies on `Deconstruct`

 Fixes dotnet#42307

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

Co-authored-by: Genevieve Warren <[email protected]>

---------

Co-authored-by: Genevieve Warren <[email protected]>
  • Loading branch information
BillWagner and gewarren authored Sep 9, 2024
1 parent fadc9f2 commit ca94fa1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/csharp/language-reference/operators/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ You use a *positional pattern* to deconstruct an expression result and match the

:::code language="csharp" source="snippets/patterns/PositionalPattern.cs" id="BasicExample":::

At the preceding example, the type of an expression contains the [Deconstruct](../../fundamentals/functional/deconstruct.md) method, which is used to deconstruct an expression result. You can also match expressions of [tuple types](../builtin-types/value-tuples.md) against positional patterns. In that way, you can match multiple inputs against various patterns, as the following example shows:
At the preceding example, the type of an expression contains the [Deconstruct](../../fundamentals/functional/deconstruct.md) method, which is used to deconstruct an expression result.

>[!IMPORTANT]
> The order of members in a positional pattern must match the order of parameters in the `Deconstruct` method. That's because the code generated for the positional pattern calls the `Deconstruct` method.
You can also match expressions of [tuple types](../builtin-types/value-tuples.md) against positional patterns. In that way, you can match multiple inputs against various patterns, as the following example shows:

:::code language="csharp" source="snippets/patterns/PositionalPattern.cs" id="MatchTuple":::

Expand Down

0 comments on commit ca94fa1

Please sign in to comment.