Synopsis: | Do NOT use the Equals method to compare diffferent value types, but use the equality operators instead. |
Language: | C# |
Severity Level: | 3 |
Category: | Object oriented |
Description: |
An example, as given below, is the best way to explain this: When the types used for int i = 0; uint ui = 0; if (i == ui) { Console.WriteLine("i == ui: true"); } else { Console.WriteLine("i == ui: false"); } if (i.Equals(ui)) { Console.WriteLine("i.Equals(ui): true"); } else { Console.WriteLine("i.Equals(ui): false"); } This code ends with the following output: i == ui: true i.Equals(ui): false |