Imagine you are a developer and your boss comes to you complaining that your piece of code has been deemed to be taking up too much memory and causing problems for the application. You take a look at your code and you see the following, assume that stream is defined above this and is correct:
const String myConstStr = "CurrentFile";
const String stylesheet = "..\\..\\XSLTFile1.xslt";
int i = 0;
for(i = 0; i < 1000; i++)
XslTransform xslt = new XslTransform();
//Load the XML data file.
String filename = myConstStr + i.ToString() + ".xml";
XPathDocument doc = new XPathDocument(filename);
//Create an XmlTextWriter to write to the stream.
XmlTextWriter writer = new XmlTextWriter(stream);
writer.Formatting = Formatting.Indented;
//Transform the file.
xslt.Transform(doc, null, writer);
So what is wrong with this snippet of code? (hint, there may be more then one thing that can be fixed).