Boxing and unboxing
So far, things look pretty straightforward. Value types live in the stack; reference types live on the heap. An integer is a value type; thus, you have it on the stack. A class you define is on the heap since that is a reference type. If you want your class to be faster, you can turn it into a struct and have it available quicker since it goes on the stack. You might be thinking this is easy, but you’d be wrong. Things can be a lot more complicated than that.
Let’s look at our good friend, the integer. An integer is a whole number, so it has no decimal point. As we saw earlier, we have a couple of variations of the integer. We have the 16-bit, the 32-bit, the 64-bit, and even a 128-bit version. And we have them in signed and unsigned versions. We even have a byte: this is technically not an integer, but since it compiles to a DWORD, we can have it in the same category. An integer is a value type, so it lives on the stack. However, if you look at...