This post originated from an RSS feed registered with .NET Buzz
by Scott Hanselman.
Original Post: Today's Minor Complaint...
Feed Title: Scott Hanselman's ComputerZen.com
Feed URL: http://radio-weblogs.com/0106747/rss.xml
Feed Description: Scott Hanselman's ComputerZen.com is a .NET/WebServices/XML Weblog. I offer details of obscurities (internals of ASP.NET, WebServices, XML, etc) and best practices from real world scenarios.
(StringReader sr = new StringReader(response))
{ try {
retVal = xs.Deserialize(sr);
}
//yada yada yada
}>
Why and this isnt?
using (XmlTextReader xr = new XmlTextReader(new
StringReader(response), /*...yada yada...*/)
{ try {
retVal = xs.Deserialize(sr);
}
//yada yada yada
}
>
Because StringReaders derive from System.IO.TextReader which implements IDisposable
and that's what the using keywords cares about. XmlTextReader derives from the
abstract XmlReader, and noone implements IDisposable. I suppose this has something
to do with closing streams in the right order, blah blah. Either way, it was
a minor sadness today.