How does string works in c#? : <p>I know strings are inmutable, once created we cannot change it, I've read that if we create a new string object and we assign a value to it and then we assign another value to the same string object internally there is actually another object created and assigned with the new value. Let's say I have:</p>

<pre><code>string str = "dog";            
str =  "cat";  
</code></pre>

<p>If I write <code>Console.WriteLine(str);</code> it returns <code>cat</code>. 
So internally there are two objects? But they have the same name? How does it works? I've made some research on google but I have not find yet something convincing enough to me so I can clarify my thoughts about this.
I know strings are reference types, so we have an object in the stack with a reference to a value in the heap, what's happening in this case?(see code above).</p>

<p>I've upload a picture, apologize me if I'm wrong about the idea of the stack and the heap that's why I'm asking this question.
Does the picture reflects what happens in the first line of code(<code>string str = "dog";</code>)? And then what should happen in the second line of code?? The <code>dog</code> value in the heap changes? And then a new object in the stack is created referencing it? Then what happens with the object that was there before? Do they have the same name?
I'm sorry for so many questions but I think that is very important to understand this correctly and to know what's happening behind the scenes...<a href="https://i.stack.imgur.com/3laO8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3laO8.png" alt="enter image description here"></a></p>
