✅ ! 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?

18 Replies
! Inverts a Boolean value
!= Is "not equal"
yep I see, what about the not pls
Well yeah, not is related
hmm related to both != and ! ? Is it the same thing as both operator in this case?
No
Ofc not
Those are not the same, so how could not be
ah true
Why not just read the documentation on patter.n matching?
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 ?
its only available in pattern matching
and it's use with is
yeah I see
you cant do
if(x is not y)
for exampleyep noted, we should use pattern matching syntax, like if (x is not . . .)
??
I mean, the "is" is a pattern matching keyword
yes
We can use the not together with "is" in this case
it can ONLY be used together with
is
oh ok, noted, thanks !