The non-ref, non-out parameter, as a local variable, indicates the storage location. If the storage location type is a reference type, then the storage location contains a reference to an instance of this type.
Feedback parameters and vice versa, on the contrary, contain a link to the storage location. This storage location can be a local variable, field, or array element. In other words, the parameters ref and out introduce another layer of indirection. If you have a reference type parameter or an output in a method, it thus represents a link to an object reference.
Why do you need a link to an object link? If you need to change the link to the object (as opposed to changing the object itself).
This is a useful technique in some narrow environments. For example, you can write a function that orders two queues, depending on which it has a lower value at the top:
void OrderQueues(ref Queue<int> a, ref Queue<int> b) { if (a.Peek <= b.Peek) return; var temp = a; a = b; b = temp; }
Options
Out are useful if you want to return more than one value from a method:
void OldestAndYoungest(IEnumerable<Person> people, out Person youngest, out Person oldest) { youngest = null; oldest = null; foreach (var person in people) { if (youngest == null || person.Age < youngest.Age) youngest = person; if (oldest == null || oldest.Age < person.Age) oldest = person; } }
In my experience, the parameters ref and out are quite rare and even less common with reference types.
Note that the ref parameter must be initialized by the caller, and the out parameter must be initialized by the called user. If you never assign a value to the ref parameter, this should probably be a βnormalβ parameter. If you never assign a value to the out parameter, as in your example, your code will not compile.