You can overload a method in a class, i.e. define two methods with the same name, if the methods have different lists of parameters. The parameter lists must differ in the number of parameters or in their types.
For example, we can overload the Dog.Bark method if the parameters differ only in type:
1 public void Bark(int numBarks)2 {3 // implementation here4 }5 6 public void Bark(short numBarks)7 {8 // implementation here9 }
We cannot overload a method if the parameters differ only in a ref vs out modifiers:
1 public void FindDog(ref Dog aDog)2 {3 // implementation here4 }5 6 public void FindDog(out Dog aDog)7 {8 // implementation here9 }
原文地址:#274 - Can't Overload if Methods Differ Only by ref and out Modifiers
新闻热点
疑难解答