Skip to content
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

Support block expressions inside pattern matching #3481

Closed
oliverjanik opened this issue May 21, 2020 · 3 comments
Closed

Support block expressions inside pattern matching #3481

oliverjanik opened this issue May 21, 2020 · 3 comments

Comments

@oliverjanik
Copy link

Version Used: C# 8

At the moment the following is not possible:

        return list.Count switch
        {
            0 => null,
            1 => list[0],
            _ => {
                LogError();
                return null;
            }
        };

I get Invalid expression term '{'

The obvious workaround here is defining a quick little private function.

@333fred
Copy link
Member

333fred commented May 21, 2020

Duplicate of #3037.

@333fred 333fred closed this as completed May 21, 2020
@svick
Copy link
Contributor

svick commented May 21, 2020

I think this is covered by the more general expression blocks proposal: #3086.

With that, your example would be:

return list.Count switch
{
    0 => null,
    1 => list[0],
    _ => {
        LogError();
        null
    }
};

@333fred
Copy link
Member

333fred commented May 21, 2020

It would be, yes, but this issue was specifically about switch expressions, unlike the general block expression proposal.

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

No branches or pull requests

3 participants