Given a method
public static string[] Foo(System.IO.Stream stream)
{
XmlTextWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.ASCII);
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("Element");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Flush();
return new string[3]{"1", "2", "3"};
}
and a calling code
using(MemoryStream memStream = new MemoryStream())
{
string[] playerIDs = PlayerCommand.Foo(stream);
// do some stuff with stream and playerIDs
}
When the control passes out of the using directive, is there a problem that xmlWriter was not explicitly closed in Foo (which would make the stream useless)?
Also, is passing a Stream between methods unsavory, is there a better way to pass the results of XMLWriting back to the calling code (which will zip it up and file it away)?
Thanks in advance, Greg