When we talked about classes and structs back in Chapter 5, Working with Classes, Structs, and OOP, we discovered that not all objects are passed the same way: value types are passed by copy, while reference types are passed by reference. However, we didn't go over how objects, or values, are used when they're passed into methods as parameter arguments.
By default, all arguments are passed by value, meaning that a variable passed into a method will not be affected by any changes that are made to its value inside the method body. While this works for most cases, there are situations where you'll want to pass in a method argument by reference; prefixing a parameter declaration with either the ref or out keyword will mark the argument as a reference.
Here are a few key points to keep in mind about using the ref keyword:
- Arguments have to be initialized before being passed into a method.
- You don't need to initialize or assign the reference parameter...