brgdotnet
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("bo ok");
4 reader.MoveToFirstAttribut e();
5 string genre = reader.Value;
6 output.AppendLine("The genre value: " + genre);
7 reader.ReadToFollowing("ti tle");
8 output.AppendLine("Content of the title element: " + reader.ReadElementContentA sString()) ;
9}
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("bo
4 reader.MoveToFirstAttribut
5 string genre = reader.Value;
6 output.AppendLine("The genre value: " + genre);
7 reader.ReadToFollowing("ti
8 output.AppendLine("Content
9}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER