Tag: 方法 解析顺序

为什么使用generics的“等于”方法解析与显式调用不同

我有以下示例: namespace ComparisonExample { class Program { static void Main(string[] args) { var hello1 = new Hello(); var hello2 = new Hello(); // calls Hello.Equals var compareExplicitly = hello1.Equals(hello2); // calls Object.Equals var compareWithGenerics = ObjectsEqual(hello1, hello2); } private static bool ObjectsEqual(TValue value1, TValue value2) { return value1.Equals(value2); } } class Hello : IEquatable { […]