TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C# Coding Standard

Rule:  7@533Checked automatically with code checker

Synopsis:Do NOT use the Equals method to compare diffferent value types, but use the equality operators instead.
Severity Level:3
Category:Object oriented


An example, as given below, is the best way to explain this:

When the types used for Equals are different, the Equals method returns false regardless of the values:

    int i = 0;
    uint ui = 0;

    if (i == ui)
      Console.WriteLine("i == ui: true");
      Console.WriteLine("i == ui: false");

    if (i.Equals(ui))
      Console.WriteLine("i.Equals(ui): true");
      Console.WriteLine("i.Equals(ui): false");

This code ends with the following output:

i == ui: true
i.Equals(ui): false