重载 和重写 没有关系

本文详细介绍了方法重载(Overloading)的概念,通过示例展示了如何在同一类型中创建多个具有相同名称但参数数量或类型不同的成员。此外,还解释了方法重写(Overriding),即在派生类中重新定义基类的虚拟方法的过程。

Member overloading means creating two or more members on the same type that differ only in the number or type of parameters but have the same name. For example, in the following, the WriteLine method is overloaded:

public static class Console {
    public void WriteLine();
    public void WriteLine(string value);
    public void WriteLine(bool value);
    ...
}


overloading        static int Add(int a ,int b) {return a+b;}             static int Add(int a, int b ,int c) { return  a+b+c; }    至于返回类型 

For example, do not do the following:

C#
C++
VB
public void Write(string message, FileStream stream){}
public void Write(string line, FileStream file, bool closeStream){}


The correct definition for these overloads is as follows:

C#
C++
VB
public void Write(string message, FileStream stream){}
public void Write(string message, FileStream stream, bool closeStream){}


看MSDN。com


overriding          是将基类定义的virtual 方法重新定义    public  virtual  void SayHello() { Console.WriteLine("Hello") }   如果没有在子类中重写这个方法,调用它将用此方法的执行逻辑, 如果在子类中重写    public override void SayHello(){  Console.WriteLine("Hello  Nier")}  将使用子方法
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值