Converting Class to XML to string
问题 I'm using XMLSerializer to serialize a class into a XML. There are plenty of examples to this and save the XML into a file. However what I want is to put the XML into a string rather than save it to a file. I'm experimenting with the code below, but it's not working: public static void Main(string[] args) { XmlSerializer ser = new XmlSerializer(typeof(TestClass)); MemoryStream m = new MemoryStream(); ser.Serialize(m, new TestClass()); string xml = new StreamReader(m).ReadToEnd(); Console