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

Don't switch on a constant #77

Closed
ddunkin opened this issue Dec 14, 2021 · 1 comment
Closed

Don't switch on a constant #77

ddunkin opened this issue Dec 14, 2021 · 1 comment

Comments

@ddunkin
Copy link
Member

ddunkin commented Dec 14, 2021

No description provided.

@bgrainger
Copy link
Member

Avoid patterns such as:

var result = true switch
{
    _ when someCondition => result1,
    _ when someOtherCondition => result2,
    _ => throw new InvalidOperationException(), // someCondition and someOtherCondition are actually mutually exclusive
}

Instead:

var result = someCondition ? result1 : result2;

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

No branches or pull requests

2 participants