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 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.

@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.

Added a code example demonstrating the use of an empty property pattern with variable creation in C#.
@AdmiralSnyder
Copy link
Contributor Author

is that sample something like what you were thinking of @BillWagner
(also, as an aside, i pinged you from another issue, dotnet/sdk#51268 (comment)
pointing you to it in case you don't get notifications about pings in issues that have already marked as completed or not planned... - could you have a look into that, by any chance?)

BillWagner and others added 2 commits October 29, 2025 12:22
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@BillWagner
Copy link
Member

Thanks @AdmiralSnyder

I did pull your branch down, and put the sample in the correct snippet folder. I'll approve and merge once the build finishes.

@BillWagner
Copy link
Member

closing and reopening to try a new build.

@BillWagner BillWagner closed this Oct 29, 2025
@BillWagner BillWagner reopened this Oct 29, 2025
@BillWagner BillWagner closed this Oct 30, 2025
@BillWagner BillWagner reopened this Oct 30, 2025
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

Thanks again @AdmiralSnyder

This LGTM, and I'll :shipit: now.

@BillWagner BillWagner merged commit e64f857 into dotnet:main Oct 30, 2025
21 of 23 checks passed
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