struct MutableCell { public string value; }
static void ArgumentPassing(string[] foo, MutableCell bar, ref string baz, ref MutableCell qux)
foo[0] = "More precisely, for reference types it is call-by-object-sharing, which is a special case of pass-by-value.";
foo = new string[]{"C# is not pass-by-reference."};
bar.value = "For value types, it is *not* call-by-sharing.";
bar = new MutableCell{value = "And also not pass-by-reference."};
baz = "It also supports pass-by-reference if explicitly requested.";
qux = new MutableCell{value = "Pass-by-reference is supported for value types as well."};
public static void Main(string[] args)
var quux = new string[]{"Yes, of course, C# *is* pass-by-value!"};
var corge = new MutableCell{value = "For value types it is pure pass-by-value."};
var grault = "This string will vanish because of pass-by-reference.";
var garply = new MutableCell{value = "This string will vanish because of pass-by-reference."};
ArgumentPassing(quux, corge, ref grault, ref garply);
Console.WriteLine(quux[0]);
Console.WriteLine(corge.value);
Console.WriteLine(grault);
Console.WriteLine(garply.value);