I'm reading John Skeet's book "C# in Depth"
. He said on page 74 that everybody suppose that arguments passing to function by reference, meanwhile it's passing by value and as example he shows this code that must prove StringBuilder in calling code wasn't changed. meanwhile inside our function StringBuilder instance changed.
private static void SayHello(StringBuilder s)
{
s.AppendLine("Hello");
}
But my experiment showing that StringBuilder object got changes - we will see "Hello" in console. What is wrong here? Or what is wrong with my understanding of this example?
private static void Main(string[] args)
{
var s = new StringBuilder();
Console.WriteLine(s.ToString());
SayHello(s);
Console.WriteLine(s.ToString());
Console.ReadLine();
}
private static void SayHello(StringBuilder s)
{
s.AppendLine("Hello");
}