In C# I need to be able to define a method but have it return one or two return types. The compiler gives me an error when I try to do it, but why isn’t it smart enough to know which method I need to call?
int x = FunctionReturnsIntOrString();
Why would the compiler prevent me from having two functions with different return types?
While it may be obvious in this particular scenario, there are many scenarios where this is in fact not obvious. Lets take the following API for an example
It’s simply not possible for the compiler to know which Foo to call in the following scenarios
These are just a few quick samples. More contrived and evil problems surely exist.