Is this:
if(x!=y)
{
}
different from this:
if (x is not y)
{
}
? Or is there no difference between the two conditions?
>Solution :
| Operator | != |
is not |
|---|---|---|
| Value inequality | Yes | Yes |
| Pattern matching types | No | Yes |
Can invoke implicit operator |
Yes | No |
| Overridable | Yes | No |
| Since | C# 1.0 | C# 9.0 |
Elided for null comparisons to value-type generic-type parameter arguments |
Yes | No[Citation needed] |
| Impossible comparisons | Error | Warning |
| Syntax | <expr> != <expr> |
<expr> is [not] <expr> [or|and <expr>]* and more |
| Example | != |
is not |
|---|---|---|
| Null example | x != null |
x is not null |
| Value inequality example | x != 'a' |
x is not 'a' |
| Runtime type (mis)match | x.GetType() != typeof(Char) |
x is not Char |