C# != Operator


Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

!= Operators C# Reference

No need to download anything, this code works in your browser

AmieDD www.amiedd.com Code, Cosplay, and Games

Operators C# Reference !=

using System;
class InequalityTest
static void Main()
// Numeric inequality:
Console.WriteLine((2 + 2) != 4);
// Reference equality: two objects, same boxed value
object s = 1;
object t = 1;
Console.WriteLine(s != t);
// String equality: same string value, same string objects
string a = "howdy";
string b = "howdy";
// compare string values
Console.WriteLine(a != b);
// compare string references
Console.WriteLine((object)a != (object)b);

About C# != Operators

The inequality operator (!=) returns false if its operands are equal, true otherwise. Inequality operators are predefined for all types, including string and object. User-defined types can overload the != operator.

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content