Skip to content
Discussion options

You must be logged in to vote

with and, or, not, > and < patterns, this is all possible in C# 9:

if(type is not (MyEnum.typeB or MyEnum.typeC or MyEnum.typeD))
{
    // do stuff
}

if(foo is "some" or "random" or "value" or "bar")
{
     // do stuff
}

const int limitA = 5;
const int limitB = 10;
var foo = 15;

if(foo is > limitA and > limitB)
{
   // do stuff
}

However it is limited to only work on constants.

Replies: 7 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@tacosontitan
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@tacosontitan
Comment options

Answer selected by YairHalberstadt
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
9 participants
Converted from issue

This discussion was converted from issue #1653 on October 16, 2020 10:24.