Corrupted string in C#
<p>I came across <em><a href="http://problembook.net/content/en/Strings/CorruptedString-S.html" rel="noreferrer">“CorruptedString” (Solution)</a></em>. Here is following code of program from the book:</p>

<pre><code>var s = "Hello";
string.Intern(s);
unsafe
{
  fixed (char* c = s)
    for (int i = 0; i &lt; s.Length; i++)
      c[i] = 'a';
}
Console.WriteLine("Hello"); // Displays: "aaaaa"
</code></pre>

<p>Why does this program display "aaaaa"? I understand this program as follows:</p>

<ol>
<li>The <a href="http://en.wikipedia.org/wiki/Common_Language_Runtime" rel="noreferrer">CLR</a> reserves "hello" in the intern pool (I image the intern pool as a set of strings).</li>
<li><code>string.Intern(s)</code> actually does nothing, because the CLR had reserved "Hello" string - it just returns address of reserved "Hello" string (object s has the same address)</li>
<li>The program changes the content of the "Hello" string via a pointer</li>
<li>??? The Hello string should be absent in the intern pool, and it should be error! But it is OK; the program runs successfully.</li>
</ol>

<p>As I understand the intern pool, it is like some kind of dictionary of string to string. Or maybe I missed something?</p>