Chapter 7: Summary

This chapter discussed how to specialize a class by deriving from it and adding additional methods and properties. This coverage included a discussion of the private and protected access modifiers that control the level of encapsulation.

The chapter also investigated the details of overriding the base class implementation and, alternatively, hiding it using the new modifier. To control overriding, C# provides the virtual modifier, which identifies to the deriving class developer which members they intend for derivation. To prevent any derivation, the sealed modifier may be used on the class. Similarly, placing the sealed modifier on a member prevents further overriding from subclasses.

This chapter briefly discussed how all types derive from object. Chapter 10 discusses this derivation in more depth, looking at how object includes three virtual methods with specific rules and guidelines that govern overloading. Before you get there, however, you need to consider another programming paradigm that builds on object-oriented programming: interfaces. This is the subject of Chapter 8.

The chapter ended with an examination of pattern matching with the is operator and both the switch statement and C# 8.0’s switch expression/statement. While C# 7.0 provided the initial pattern matching support, all versions through C# 11 have expanded these capabilities.

{{ snackbarMessage }}
;