<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Dispose on an IList?</title><link>http://blogs.msdn.com/brada/archive/2004/06/25/166527.aspx</link><description>A developer on an internal alias asks: I&amp;#8217;m using an API which returns an IList of objects which have to be Disposed. Are there any pitfalls I should be aware of, or can I just use a foreach like the following? foreach (Thing myThing in myList) {</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Dispose on an IList?</title><link>http://blogs.msdn.com/brada/archive/2004/06/25/166527.aspx#166641</link><pubDate>Sat, 26 Jun 2004 08:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:166641</guid><dc:creator>Chris Nahr</dc:creator><description>Maybe I don't understand the issue but are you sure you answered the question?&lt;br&gt;&lt;br&gt;I think you talked about disposing the _enumerator_ while the question was disposing of the _elements_ of the list. Enumerators don't touch the elements at all. Neither does yours, as far as I can tell.&lt;br&gt;&lt;br&gt;If you were thinking about disposing of elements in the Dispose method of an enumerator... well, that's code obfuscation on a C++ level if you ask me. :) The foreach loop proposed by the reader should do the job just fine.</description></item><item><title>re: Dispose on an IList?</title><link>http://blogs.msdn.com/brada/archive/2004/06/25/166527.aspx#166898</link><pubDate>Sat, 26 Jun 2004 17:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:166898</guid><dc:creator>Brad Abrams</dc:creator><description>Yea, you are right... I said it was a parital answer... I wounder if you can restructure the problem such that the enumerator holds the resources that need to be freed...</description></item><item><title>re: Dispose on an IList?</title><link>http://blogs.msdn.com/brada/archive/2004/06/25/166527.aspx#167107</link><pubDate>Sun, 27 Jun 2004 07:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:167107</guid><dc:creator>Chris Nahr</dc:creator><description>Not sure you could do anything (sensible) with the enumerator. What I would do is create a wrapper object that can be disposed of wholesale, thereby disposing of all the elements in the wrapped collection. That way you could use a single using statement, just like when you're opening a file or showing a dialog.</description></item><item><title>re: Demystifying Dispose</title><link>http://blogs.msdn.com/brada/archive/2004/06/25/166527.aspx#232845</link><pubDate>Wed, 22 Sep 2004 17:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:232845</guid><dc:creator>Chris Lyon's WebLog</dc:creator><description /></item><item><title>C# foreach and Dispose</title><link>http://blogs.msdn.com/brada/archive/2004/06/25/166527.aspx#431957</link><pubDate>Thu, 23 Jun 2005 20:46:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:431957</guid><dc:creator>Security Briefs</dc:creator><description /></item></channel></rss>