I've been reading up on value- and reference types as well as the ref
keyword, with special attention to this post: C# string reference type?. Jon Skeet's answer "The reference to the string is passed by value. There's a big difference between passing a reference by value and passing an object by reference. It's unfortunate that the word "reference" is used in both cases." confuses me even after his example.
Consider this:
string x = "foo";
void Bar(string s)
{
Console.Write(s);
}
Bar(x);
My question: when passing x
to Bar
, does s
represent a full copy of x
in memory or is s
a pointer to x
? This becomes relevant if x
is really large. Would there be a performance benefit in passing x
by ref
when all I want to do is transform s
into something different (without changing s
itself?)