December 19, 2019

The four kinds of a reference

This article applies not only to C#, but also to other languages with references, like C++.

A reference is a special type that allows you to access data stored in another location separate from the variable that contains the reference. When accessing a reference variable, indirection is automatically performed, i.e. first the actual address to the remote variable is fetched, then the object stored in the variable is accessed. This behaviour is distinct from pointers, which employ the same indirection mechanisms, but are treated as normal values and so dereferencing must be explicit.