Memory management
As I mentioned at the start of this chapter, structures are value types and classes are reference types. What this means is that when we pass an instance of a structure within our application, such as a parameter of a method, we create a new instance of the structure in the memory. This new instance of the structure is only valid while the application is in the scope where the structure was created. Once the structure goes out of scope, the new instance of the structure is destroyed and the memory is released. This makes memory management of structures pretty easy and somewhat painless.
Classes, on the other hand, are of the reference type. This means that we allocate memory for the instance of the class only once-when it is initially created. When we want to pass an instance of the class within our application, either as a function argument or by assigning it to a variable, we really pass a reference to where the instance is stored in memory. Since the instance of a class...