Say I have the following code:
void Main()
{
int a = 5;
f1(ref a);
}
public void f1(ref int a)
{
if(a > 7) return;
a++;
f1(ref a);
Co
Adding to the existing answers how this is implemented:
The CLR supports so called managed pointers. ref
passes a managed pointer to the variable on the stack. You can also pass heap locations:
var array = new int[1];
F(ref array[0]);
You can also pass references to fields.
This does not result in pinning. Managed pointers are understood by the runtime (in particular by the GC). They are relocatable. They are safe and verifiable.