重载OverLoad。隐藏new

<1>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{

    class A
    {
        public void SayHello()
        {
            Console.WriteLine("我是父类的SayHello方法");
        }
    }

    class B : A
    {
        public new void SayHello() //子类利用newkeyword隐藏了父类的同名方法
        {
            Console.WriteLine("我是子类的SayHello方法");
        }
    }


    //构成方法重载的条件:<1>:函数名同样  <2>:參数类型不同,或者參数个数不同
    //注意:函数返回值类型的不同 不是函数重载的推断条件。
    class C
    {
        public void Add(int a,int b)   //下面4个Add方法构成了重载
        {
            Console.WriteLine(a + b);
        }
        public double Add(double a, double b)
        {
            return a + b;
        }
        public void Add(int a)
        {
            Console.WriteLine(a);
        }

        public string Add(string a, string b)
        {
            return a + b;
        }
    }
    class Inheritance
    {
        static void Main(string[] args)
        {

            B b = new B();
            b.SayHello();



            Console.ReadKey();
        }
    }
}

原文地址:https://www.cnblogs.com/yxysuanfa/p/7162025.html