title: MemoryStream from string - confusion about Encoding to use
body: <p>I have a piece of code that converts string into memory stream:</p>
  
  <pre><code>using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(applicationForm)))
  </code></pre>
  
  <p>However I'm a bit confused if it's correct. Basically I'm always confused about .NET encoding.</p>
  
  <p>Bottom line: do I use correct encoding object (<strong>UTF8</strong>) to get bytes? </p>
  
  <p>I know that internally .NET stores string as <strong>UTF-16</strong>, but my <strong>applicationForm</strong> variable was based on file with text which was saved in <strong>UTF-8</strong> encoding. </p>
  
  <p>Thanks,Pawel</p>
  
  <p>EDIT 1: Let's explain exactly how I get <strong>applicationForm</strong> variable. I do have access to assembly that exposes class with method <strong>GenerateApplicationForm</strong>. That method returns string. However I know, that somewhere behind the scenes, component uses files stored on drive.Content of those files are encoded using UTF-8. So I can't read file directly etc. I only have that string and I know, that originally, UTF-8 encoded file is used.
  In client code, the one that used <strong>GenerateApplicationForm</strong> component, I have to convert <strong>applicationForm</strong> variable into stream, cos other components (from another assembly) is expecting a <strong>Stream</strong>. That's where <strong>using....</strong> statement mentioned in question springs into action.</p>