title: Clearing a System.String in C#
body: <p>Will this overwrite the contents of my string:</p>
  
  <pre><code>unsafe
  {
      fixed (char* chars = str)
      {
          for (int i = 0; i &lt; str.Length; i++)
              chars[i] = '1';
      }
  }
  </code></pre>
  
  <p>The background is I'm using <a href="http://msdn.microsoft.com/en-us/library/system.net.networkcredential%28v=vs.110%29.aspx" rel="noreferrer">NetworkCredientials</a>, in which you set the password using a plain old <code>System.String</code>. I'd like to "clear it" afterwards, if that's possible. Any suggestions on how to do this are welcome, but the main question is to understand if <code>fixed</code> will really give me access to the underlying char array. Thanks!</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I would like to understand what <em>is</em> going on here - if a string object is immutable, and <code>fixed</code> doesn't let the object move then what's happening in the code posted? Where are those characters being written to?</p>