title: Can I Serialize XML straight to a string instead of a Stream with C#?
body: <p><a href="http://bytes.com/groups/net-xml/177700-how-do-i-serialize-object-string-instead-stream" rel="noreferrer">This example</a> uses a <code>StringWriter</code> to hold the serialized data, then calling <code>ToString()</code> gives the actual <code>string</code> value:</p>
  
  <pre><code>Person john = new Person();
  XmlSerializer xmlSerializer = new XmlSerializer(typeof(Person));
  StringWriter stringWriter = new StringWriter();
  xmlSerializer.Serialize(stringWriter, john);
  string serializedXML = stringWriter.ToString();
  </code></pre>
  
  <p>Is there any easier/Cleaner way to do this?  All of the <code>Serialize()</code> overloads seem to use a <code>Stream</code> or Writer.</p>
  
  <p><strong>UPDATE:</strong> Asked a similar question about <a href="https://stackoverflow.com/questions/1138667/extension-method-for-serializing-an-ienumerablet-object-to-a-string-array">serializing an IEnumerable via an Extension Method</a> .</p>