Link to home
Start Free TrialLog in
Avatar of brgdotnet
brgdotnetFlag for United States of America

asked on

Use of "Using" statement for IDisposable

I am reading some Microsoft documentation on XmlReader. The documentation is great, however I am looking for an explanation as to why they choose to implement the
use of a using statement at line 1? I read the documentation on the "using" statement, and it seems to be geared twords when you are using IDisposable:


https://msdn.microsoft.com/en-us/library/yh598w02.aspx

Does XmlReader implement the IDisposable object? If I had to explain to someone else why a using statement is used at line 1 below, I really could not do it. Perhaps someone can help me to understand.

https://msdn.microsoft.com/en-us/library/cc189056(v=vs.95).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-4


// Create an XmlReader
1   using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
2 {
3    reader.ReadToFollowing("book");
4    reader.MoveToFirstAttribute();
5    string genre = reader.Value;
6    output.AppendLine("The genre value: " + genre);

 7   reader.ReadToFollowing("title");
 8   output.AppendLine("Content of the title element: " + reader.ReadElementContentAsString());
9}
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brgdotnet

ASKER

Russ you Rock. Thanks