Overloading == to return a non-boolean
Were you aware that you could overload == to return types other than boolean? I certainly wasn’t until I started reading through the lifted operators part of the C# 2 specification. It’s quite bizarre – here it is in action: using System; class Test { public static string operator== (Test t1, Test t2) { return “Fish?”; } public static string operator!= (Test t1, Test t2) { return “Not a fish?”; } static void Main() { Test a = new Test(); Test b = new Test(); Console.WriteLine (a==b); } } That ends up printing “Fish?” to the console. Strange but true. … Continue reading Overloading == to return a non-boolean