Skip to content

unions.md: Expand usage of TryGetValue(Nullable<T>) methods for a pattern that implies checking for a specific type T#10098

Open
AlekseyTs wants to merge 1 commit into
mainfrom
AlekseyTs-patch-8
Open

unions.md: Expand usage of TryGetValue(Nullable<T>) methods for a pattern that implies checking for a specific type T#10098
AlekseyTs wants to merge 1 commit into
mainfrom
AlekseyTs-patch-8

Conversation

@AlekseyTs

Copy link
Copy Markdown
Contributor

Otherwise the following scenario doesn't use TryGetValue:

[System.Runtime.CompilerServices.Union]
struct S1
{
    private readonly object _value;
    public S1(int? x) { _value = x; }
    public S1(string x) { _value = x; }
    public object Value => _value;
    public bool TryGetValue(out int? x) { if (_value is int v) { x = v; return true; } x = null; return false; }

    static bool Test1(S1 u)
    {
        return u is int;
    }   
}

…attern that implies checking for a specific type `T`
@AlekseyTs
AlekseyTs requested a review from MadsTorgersen April 13, 2026 15:41
@AlekseyTs
AlekseyTs requested a review from a team as a code owner April 13, 2026 15:41

@MadsTorgersen MadsTorgersen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're right, good catch!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants