To remain in the scope of this course, we won’t be getting into the nitty-gritty of the difference between value types and reference types. All you need to know is that for a value type, the information it provides is the value itself. For a reference type, the information it provides is a reference to some object, i.e., the memory address of an object. To make this clearer, let’s look at this using physical objects.
svg viewer
Imagine you have a piece of paper. You want the paper to hold some information, such as your name. You can write your name on the piece of paper; therefore the value of the paper is the same as the information it provides. This is an example of value type. If someone wants to know your name, all they have to do is read the paper.
Now imagine, you want the paper to hold your house. That’s not physically possible, so you write the address to your house, hence the value of the paper is a reference to the required information. This is an example of reference type. If someone wants to go to your house, they will first have to read the directions to your house.
In the same way, a reference type holds the memory address location of the value, while value types hold the value themselves.
The focus of this chapter is value types.