Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm refactoring the following code:

C#
using (StreamReader stream = new StreamReader(InputFilePath))
{
    XmlTextReader xmlIn = new XmlTextReader(stream);
    while (xmlIn.Read())
    {
        //Do stuff
    }
    xmlIn.Close();
}


First I'm, being a bit paranoid and want to check if the following will behave, as I'm unsure why this wasn't done in the originally:
C#
using (XmlTextReader xmlIn = new XmlTextReader(new StreamReader(inputFilePath)))
{
    while (xmlIn.Read())
    {
        //Do stuff
    }
}


Secondly, I also vauguely remember there is a neater way than the new XmlTextReader(new StreamReader(inputFilePath))
instantiation, if I'm right suggestions would be useful.

Thanks.
Posted
Comments
[no name] 21-Nov-10 7:59am    
Dont you think that everybody is not so intelligent and rude as you. Now its my voting 1 for you are intelligent 5 for your behave.
Keith Barrow 21-Nov-10 11:25am    
@Sunil, go ahead, vote one, my reputation (if I were actually worried about it) will take it. I'm one of the regulars here, and I can tell you, with your current attitude you can expect precious little help. I've seen your sort of behaviour here before, and no-one stands for it.

1 solution

I would be tempted to leave it as it is.
Does dispose on the XmlTextReader also dispose the stream? I know XmlTextReader implements IDisposable (via XmlReader), but I think it is clearer that the stream is disposed (which is the important bit) with the first version.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900