Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
C# != Operator Tutorial
This C# != Operator Tutorial www.amiedd.com AmieDD - code, cosplay and games
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
class InequalityTest
{
static void Main()
{
// Numeric numbers that don't equal:
Console.WriteLine((2 + 2) != 4);
// Reference equality, two objects, same value
object s = 1;
object t = 1;
Console.WriteLine(s != t);
// Strings, 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);
}
}
/*
Output:
False
True
False
False
*/
Enter to Rename, Shift+Enter to Preview
About C# != Operators
!= Not equal.Predefined value types, the inequality operator (!=) returns true if the values are different, false. If the reference types isn't a string, != returns true if its two operands points to different objects. String type, != compares the values of the strings.
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content