I never knew: C# method overloads can return different types
I came to C# from Java, which I’m pretty sure doesn’t (or maybe didn't) allow this, so I was super surprised today when I learnt that C# method overloads can have different return types.
So this class is completely valid:
public class Foo
public Foo Bar();
public string Bar(Foo foo);
For years I’ve thought all overloads had to return the same type, so I’ve designed around a non-existent limitation !
So I’m wondering if any of the APIs I’ve designed over the years would have been ‘better’ if I’d realized this sooner?
What do you think? Is it a good idea to do this?