How can I hide a base class public property in the derived class

后端 未结 16 1504
自闭症患者
自闭症患者 2021-01-01 08:39

I want to hide the base public property(a data member) in my derived class:

class Program
{
    static void Main(string[] args)
    {
        b obj = new b()         


        
16条回答
  •  攒了一身酷
    2021-01-01 09:08

    You can user new modifer.

    Sample;

    public class Duck
    {
        public string Color{get; set;}
        public void Swim() { }
    }
    public class DonaldDuck : Duck
    {
        new public void Swim() 
        { 
            /*you could call in DonaldDuck.Swim  only here but not public for DonaldDuck client.*/ 
        }
    }
    

提交回复
热议问题