隐藏继承类中的虚函数

Rai*_*ika 3 c# oop inheritance

我有一个继承自的课程,LinkButton我想隐藏OnClinentClick在课堂上.

像这样的东西:

public class MyClass : LinkButton
{
    // some Code
}
Run Code Online (Sandbox Code Playgroud)

代码中的某处:

MyClass myclass = new MyClass();
MyClass.OnClinentClick = "";//this line must not be accessable
Run Code Online (Sandbox Code Playgroud)

Fem*_*ref 6

不直接支持隐藏类定义中的某些内容,因为它违反了OOP原则.

您可以使用new运营商,但我不建议.就个人而言,NotSupportedException如果没有别的办法,我会考虑我的设计和/或使用a .

  • 我不认为`NotImplementedException`是正确的选择.IMO它应该是`NotSupportedException`.当你还没有编写代码时,没有实现. (3认同)