Skip to content

Conversation

@AdmiralSnyder
Copy link
Contributor

@AdmiralSnyder AdmiralSnyder commented Oct 21, 2025

Clarify the behavior of the empty property pattern in C#.

Summary

added note about the empty property pattern because it wasn't mentioned anywhere.


Internal previews

📄 File 🔗 Preview link
docs/csharp/language-reference/operators/patterns.md Pattern matching - the is and switch expressions, and operators and, or, and not in patterns

Clarify the behavior of the empty property pattern in C#.
@Copilot Copilot AI review requested due to automatic review settings October 21, 2025 13:44
@AdmiralSnyder AdmiralSnyder requested review from a team and BillWagner as code owners October 21, 2025 13:44
@dotnetrepoman dotnetrepoman bot added this to the October 2025 milestone Oct 21, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds clarification about the behavior of the empty property pattern (is { }) in C#, which was previously undocumented in the patterns documentation.

Key Changes:

  • Added a note explaining that the empty property pattern is { } matches all non-null values and can be used as an alternative to is not null for creating variables.


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

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`.
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'specifially' to 'specifically'.

Suggested change
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`.
This specifically 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`.

Copilot uses AI. Check for mistakes.

@dotnet-policy-service dotnet-policy-service bot added dotnet-csharp/svc lang-reference/subsvc community-contribution Indicates PR is created by someone from the .NET community. labels Oct 21, 2025
@BillWagner
Copy link
Member

Hi @AdmiralSnyder

I like this change. I think it would be more clear to readers if you added an example of is { } as a null check. Can you make that addition?

@AdmiralSnyder
Copy link
Contributor Author

hi @BillWagner i didn't know how the
:::code language="csharp" source="snippets/patterns/PropertyPattern.cs" id="WithTypeCheck":::
worked, or rather, how i add a second file into the commit/PR from the github UI (using the convenient "edit" function) - you mean, that, right?

or do you mean just expanding the inline code ?

@BillWagner
Copy link
Member

@AdmiralSnyder

Adding a second file in the same PR isn't easy in the GitHub UI. If you add an inline example, I'll move it to the included snippets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates PR is created by someone from the .NET community. dotnet-csharp/svc lang-reference/subsvc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants