我怎样才能不让自己被继承在C#中的一类?

2023-09-04 08:47:22 作者:网污

在Java中,我可以用最终关键字做到这一点。我没有看到最终在C#。是否有替代品?

In java, I could do this with the 'final' keyword. I don't see 'final' in C#. Is there a substitute?

推荐答案

您正在寻找的密封关键字。这不正是 Java中的最后一个关键字一样。试图继承会导致编译错误。

You're looking for the sealed keyword. It does exactly what the final keyword in Java does. Attempts to inherit will result in a compilation error.

相关推荐