I was considering using a struct to store several bits of state inside a method, however I wanted to be able to pass this to a helper method using the ref
keword to avoid passing by value. If I do that however, will then be stored on the heap, rather than the stack?
example code:
var link = new Geoff("Bergen");
Perambulate(ref link);
Console.WriteLine(link.Name);
void Perambulate(ref Geoff man)
{
Console.WriteLine("Perambulating {0}",man.Name);
}
struct Geoff
{
public readonly string Name;
public Geoff(string name)
{
Name = name;
}
}
I guess I'm really asking if the ref
keyword forces the referenced value to be stored on the heap.