If you call the overload of Create on XmlReader that takes just a
TextReader implementation, then no, the XmlReader will not close the
underlying reader. You have to pass an XmlReaderSettings to the Create
method setting the CloseInput property to true.
It's probably not the worst idea in the world though to use it in a
using statement, even though you are using a StringReader. By skipping it
(kind of like not calling Dispose on the DataSet) you are coding based on an
implementation detail, which as we all know, is bad (as a general statement,
of course, there are instances where you are forced to code against
implementation details).
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
Aneesh Pulukkul[MCSD.Net] <an******@gmail.comwrote:
>One more thing, while dealing with streams, be sure that we close/
dispose the stream objects properly else we'll get he access denied/
file is in use by another process issues.
new XmlTextReader(new
MemoryStream(ASCIIEncoding.Default.GetBytes(myXML string))); // Create
a memory stream object and dispose it.
I would suggest using the 'using' scope. E.g.
While I would normally agree with you, there are no files involved here
in the first place - with both MemoryStream and StringReader, the only
resources involved are in memory.
When using XmlReader, I believe that closing the XmlReader will close
any streams it's been passed.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too