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

后端 未结 16 1573
自闭症患者
自闭症患者 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:06

    If you use an interface instead of a base class for defining the property, you could implement the property explicitly. The would require an explicit cast to the interface to use the property.

    public interface IMyInterface
    {
        string Name { get; set; }
    }
    
    public class MyClass : IMyInterface
    {
    
        string IMyInterface.Name { get; set; }
    
    }
    

    You can find more out here.

提交回复
热议问题