Understanding values and references

Summary

In this chapter, you learned about some important differences between value types that hold their value directly on the stack and reference types that refer indirectly to their objects on the heap. You also learned how to use the ref and out keywords on method parameters to gain access to the arguments. You saw how assigning a value (such as the int 42) to a variable of the System.Object class creates a boxed copy of the value on the heap and then causes the System.Object variable to refer to this boxed copy. You also saw how assigning a variable of a value type (such as an int) from a variable of the System.Object class copies (or unboxes) the value in the System.Object class to the memory used by the int.

  • If you want to continue to the next chapter, keep Visual Studio 2017 running and turn to Chapter 9.

  • If you want to exit Visual Studio 2017 now, on the File menu, click Exit. If you see a Save dialog box, click Yes and save the project.