-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored CS0077 Example with Modern C# Pattern Matching #43108
Conversation
@shethaadit Why submitting a PR to an issue that already has a comment saying someone is working on it? |
@BartoszKlonowski, I understand your concern. However, since the issue has been idle for over a week without updates, I decided to step in to keep progress moving. Let me know and I can abandon this PR. |
@shethaadit No need to abandon, since you already spent some time on it. |
Thank you for the suggestion. Updating it. Co-authored-by: Bartosz Klonowski <70535775+BartoszKlonowski@users.noreply.github.com>
Co-authored-by: Bartosz Klonowski <70535775+BartoszKlonowski@users.noreply.github.com>
Co-authored-by: Bartosz Klonowski <70535775+BartoszKlonowski@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me 👍
Sorry the fuss at the beginning, @shethaadit and thank you for handling this!
Let's hear from @BillWagner if there's something to improve.
Thank you @BartoszKlonowski for your suggestions. Appreciate your help and support. :) Hi @BillWagner, please let me know if this PR looks okay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. I had one grammar note, and then I'll
Summary
PR Description:
This PR introduces a significant improvement to the existing example for resolving
CS0077
, showcasing the transition from the traditionalas
operator to modern C# pattern matching (is
) for value types.While the as operator is traditionally used for safe casting of reference types, applying it to non-nullable value types, such as structs, results in the
CS0077
compiler error. This update replaces the outdated approach with cutting-edge pattern matching techniques, fully embracing the capabilities of C#'s modern syntax.Key Highlights:
as
on a value type with pattern matching usingis
.is
.By leveraging modern C# features, this refactor not only resolves the outdated issue but also elevates the educational value of the example, leading to more robust, readable, and maintainable code in future C# projects.
Fixes #42861
Internal previews