Groups | Blog | Home
all groups > dotnet xml > july 2004 >

dotnet xml : XmlTextReader instances - help


Timothy V
7/19/2004 11:58:11 AM
Hi,
When you create an instance of an XmlTextReader and give it a file to open
(constructor), does it automatically close the file when the destructor is
invoked (ie. automatically invokes method Close() when destructing)? Or do I
have to invoke the Close() method myself to close the file?

Thank you in advance,

Tim.

Oleg Tkachenko [MVP]
7/19/2004 1:49:54 PM
[quoted text, click to view]

XmlTextReader doesn't have a destructor and doesn't implement
IDisposable. So you have to call Close() once you done with
XmlTextReader instance.

--
Oleg Tkachenko [XML MVP]
Oleg Tkachenko [MVP]
7/19/2004 2:58:00 PM
[quoted text, click to view]

With regard to the undetermenistic nature of object destruction in .NET
that would be highly ineffective.
In .NET 2.0 instead XmlReader implements IDisposable interface, so you
can get automatic closing when using "using" statement in C#.

--
Oleg Tkachenko [XML MVP]
Timothy V
7/19/2004 9:44:09 PM
Thanks, but i would have thought it logical to automatically close the file
once the instance no longer exists. Oh well...

[quoted text, click to view]

AddThis Social Bookmark Button