C
C#3mo ago
cypherpotato

✅ Disjunctive patterns negation

Hey there. I was wondering why my disjunctive is not working as intended:
authUser.Level
> Internal
authUser.Level is UserLevel.Administrator
> false
authUser.Level is UserLevel.Internal
> true
authUser.Level is not UserLevel.Administrator or UserLevel.Internal
> true
authUser.Level
> Internal
authUser.Level is UserLevel.Administrator
> false
authUser.Level is UserLevel.Internal
> true
authUser.Level is not UserLevel.Administrator or UserLevel.Internal
> true
The last expression result doesn't make sense for me, because I'm checking if authUser.Level is not Administrator or Internal, and it actually is Internal as shown in the first expression, so the result should be false. What i'm doing wrong?
10 Replies
Keswiik
Keswiik3mo ago
probably need to use parenthesis around your or for the not to function as expected
cypherpotato
cypherpotato3mo ago
C# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
cypherpotato
cypherpotato3mo ago
but why putting an parenthesis on it? does (UserLevel.Administrator or UserLevel.Internal) produces an enum with equality to both values or am i missing something else?
Keswiik
Keswiik3mo ago
Because your example shows that it is clearly matching against not UserLevel.Administrator and UserLevel.Internal
cypherpotato
cypherpotato3mo ago
so the ideal, without the parenthesis, would be authUser.Level is not UserLevel.Internal and not UserLevel.Administrator?
Keswiik
Keswiik3mo ago
correct
cypherpotato
cypherpotato3mo ago
pretty confusing but that's it, thank you
Keswiik
Keswiik3mo ago
:PepoSalute:
Denis
Denis3mo ago
$close
MODiX
MODiX3mo ago
Use the /close command to mark a forum thread as answered