Sealing and Hiding: Take Two

As previously mentioned, the sealed keyword prevents a class from being derived any further. We can also apply such specialization prevention at a more granular level of members, too. For example, while we may leave our Square type unsealed (the default), we can prevent people from overriding the virtual properties we’ve defined:

image

Now if someone comes in and defines a subclass of Square, say ColoredSquare, it’s no longer possible to override the computation properties Area or Circumference.

With regard to hiding using the new modifier, it’s possible to hide an inherited member, including virtual ones, but the combination ...

Get C# 4.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.