Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a difference between "!=" and "is not" in C#?

Is this:

if(x!=y)
{

}

different from this:

if (x is not y)
{

}

? Or is there no difference between the two conditions?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading