首页 > 学院 > 开发设计 > 正文

【转载】#274

2019-11-17 03:18:45
字体:
来源:转载
供稿:网友

【转载】#274 - Can't Overload if Methods Differ Only by ref and out Modifiers

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表