Coffeehouse Post

Single Post Permalink

View Thread: Why does C# not support this?
  • User profile image

    Overloads aren't discriminated on return types in any language I know of. There are good reasons for it.


    It would mean you'd need to have a "target type" for an expression in order to resolve which overload to use. That's OK in a trivial example such as yours where you can take it from the LHS of the assignment, but what about when you are evaluating a subexpression with overloads based on return type and that subexpression is passed as a parameter to function for which there are multiple overloads - which do you chose then?