Method Overloading with different return type

Viewed 65588

I am want to dig in that whether it is an ambiguity or an extra feature that is provided:

 public class Foo 
 { 
    public int Bar(){
       //code
    }

    public string Bar(int a){
       //code
    }
 }

Any one having any experience with this, overloading on return type with different parameters should be a bad practice, is it?

But if the overloading was done on the basis of return type then why this is not working for.

 public class Foo 
 { 
    public int Bar(int a){
       //code
    }

    public string Bar(int a){
       //code
    }
 }

As it will be unable to decide which function to call 1st or second, if we call obj.Bar(); , it should end in error do any one have any idea about it why it allows first code snippet to run.

9 Answers
Related