How to hide an inherited property in a class without modifying the inherited class (base class)?

前端 未结 10 1074
无人共我
无人共我 2020-11-27 20:21

If i have the following code example:

public class ClassBase
{
    public int ID { get; set; }

    public string Name { get; set; }
}

public class ClassA :         


        
10条回答
  •  感情败类
    2020-11-27 20:38

    You can't, that's the whole point of inheritance: the subclass must offer all methods and properties of the base class.

    You could change the implementation to throw an exception when the property is called (if it were virtual)...

提交回复
热议问题