0
using System;
using System.Text;

namespace Objects
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder x = new StringBuilder(), y = x;
            x.Append("Hello, ");
            y.Append("World");
            Console.WriteLine(x.ToString());//prints Hello, World
            Console.WriteLine(y.ToString());//prints Hello, World
            x = null;
            Console.WriteLine(x); // produces NullString
            Console.WriteLine(y.ToString()); //prints Hello, World.How does it print Hello, World
            Console.ReadLine();

        }
    }
}
xanatos
  • 109,618
  • 12
  • 197
  • 280
  • They are references to the same stringbuilder – EpicKip Mar 17 '17 at 12:12
  • 4
    @EpicKip No, the fine point is that `x` and `y` are distinct references to the same `StringBuilder`, and he is `null`(ing) only `x`. The `y` reference is still referencing the `StringBuilder` – xanatos Mar 17 '17 at 12:13
  • @xanatos While your explanation is more in depth and explain how the nulling works, my statement is still not incorrect :) – EpicKip Mar 17 '17 at 12:15

0 Answers0