C
C#2mo ago
Faker

✅ ! vs != and not operators in C#

Hello guys, can someone explain what's the difference between the ! and != operator in C# please. Also, I noticed that C# has a not operator in pattern matching; is it related to the ! or !=? For example here, my IDE is telling me to use "negated pattern"; this mean to use the not keyword?
No description
18 Replies
Pobiega
Pobiega2mo ago
! Inverts a Boolean value != Is "not equal"
Faker
FakerOP2mo ago
yep I see, what about the not pls
Pobiega
Pobiega2mo ago
Well yeah, not is related
Faker
FakerOP2mo ago
hmm related to both != and ! ? Is it the same thing as both operator in this case?
Pobiega
Pobiega2mo ago
No Ofc not Those are not the same, so how could not be
Faker
FakerOP2mo ago
ah true
Pobiega
Pobiega2mo ago
Why not just read the documentation on patter.n matching?
Faker
FakerOP2mo ago
yeah I started a bit 😅 , will just finish it Will come back if I have some doubts I read that the not is a "logical pattern"; can we say it's the same thing as the "!" then ? just it's more readable/user-friendly ?
Pobiega
Pobiega2mo ago
its only available in pattern matching
Faker
FakerOP2mo ago
and it's use with is yeah I see
Pobiega
Pobiega2mo ago
you cant do if(x is not y) for example
Faker
FakerOP2mo ago
yep noted, we should use pattern matching syntax, like if (x is not . . .)
Pobiega
Pobiega2mo ago
??
Faker
FakerOP2mo ago
I mean, the "is" is a pattern matching keyword
Pobiega
Pobiega2mo ago
yes
Faker
FakerOP2mo ago
We can use the not together with "is" in this case
Pobiega
Pobiega2mo ago
it can ONLY be used together with is
Faker
FakerOP2mo ago
oh ok, noted, thanks !

Did you find this page helpful?