Equality

Are the variables (or objects) equal.


Operator - ==

Can be used to compare both value and reference data types.
For value types this returns true if the values are equal
For the string reference type this compares the contents.
For all other reference types this compares the identity on the heap.

if (svalue1 == svalue2) 
{
}
If (svalue1 = svalue2) Then 
End If


Operators - !=

Are the variables different

if (ovalue1 != null) 
{
}
If ( Not (objMyObject Is Nothing) ) Then 
If (objMyObect IsNot Nothing) Then

Equals() Method

Can be used to compare both value and reference data types.
For all types this compares the contents (not the identity on the heap)
Also known as testing for equality without coalescing

If (svalue1.Equals(svalue2)) 
{
}

You should always use the Equals() method to check reference types for equality



© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext