From ca94fa110cab32a7558aed61de644dc19cd4f6aa Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Mon, 9 Sep 2024 13:54:34 -0400 Subject: [PATCH] Make it more clear that a positional pattern relies on `Deconstruct` (#42514) * Make it more clear that a positional pattern relies on `Deconstruct` Fixes #42307 * Update docs/csharp/language-reference/operators/patterns.md Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --------- Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- docs/csharp/language-reference/operators/patterns.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/operators/patterns.md b/docs/csharp/language-reference/operators/patterns.md index a4579eddab2f7..599d40e70d7a2 100644 --- a/docs/csharp/language-reference/operators/patterns.md +++ b/docs/csharp/language-reference/operators/patterns.md @@ -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":::