10.1 Introduction

In this chapter, we take a deeper look at building classes, controlling access to members of a class and creating constructors. We discuss composition—a capability that allows a class to have references to objects of other classes as members. The chapter also discusses static class members and readonly instance variables and properties.

We also introduce operator overloading. In previous chapters, we declared our own classes and used methods to perform tasks on objects of those classes. Operator overloading allows us to define the behavior of the built-in operators, such as + and -, when used on objects of our own classes. This can provide a more convenient notation than calling methods for performing certain tasks (such as arithmetic) using objects.

We show how to create your own value types using struct, discuss key differences between structs and classes, and discuss when struct types should be used. Finally, we demonstrate how to create your own extension methods to add functionality to an existing type that you did not define.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset