<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Puzzling over arrays and enumerators in C#</title>
	<atom:link href="http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/</link>
	<description>On programming, technology, and random things of interest</description>
	<lastBuildDate>Thu, 29 Jul 2010 00:28:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Igor Ostrovsky</title>
		<link>http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/comment-page-1/#comment-832</link>
		<dc:creator>Igor Ostrovsky</dc:creator>
		<pubDate>Fri, 19 Mar 2010 06:41:56 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/#comment-832</guid>
		<description>Paul J: Thanks for the reminder. I updated the article with the solution.</description>
		<content:encoded><![CDATA[<p>Paul J: Thanks for the reminder. I updated the article with the solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vitali Climenco</title>
		<link>http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/comment-page-1/#comment-829</link>
		<dc:creator>Vitali Climenco</dc:creator>
		<pubDate>Thu, 18 Mar 2010 07:56:24 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/#comment-829</guid>
		<description>To my mind, the simplest way to make the code compile would be to declare e as IEnumerable. Also, instead of System.Collections.Generic, the code should use  System.Collections because IEnumerable resides there. So, the updated code would become:

   using System.Collections;
   class Program
   {
       public static void Main()
       {
           int[] arr = new int[10];
           IEnumerator e = arr.GetEnumerator();
       }
   }

I think the described behavior is perfectly reasonable. arr.GetEnumerator()&#040;s return type is actually SZArrayEnumerator. Although SZArrayEnumerator and IEnumerator&lt;T&gt; both implement IEnumerator, they are different types and cannot cast implicitly to each other.</description>
		<content:encoded><![CDATA[<p>To my mind, the simplest way to make the code compile would be to declare e as IEnumerable. Also, instead of System.Collections.Generic, the code should use  System.Collections because IEnumerable resides there. So, the updated code would become:</p>
<p>   using System.Collections;<br />
   class Program<br />
   {<br />
       public static void Main()<br />
       {<br />
           int[] arr = new int[10];<br />
           IEnumerator e = arr.GetEnumerator();<br />
       }<br />
   }</p>
<p>I think the described behavior is perfectly reasonable. arr.GetEnumerator()&#40;s return type is actually SZArrayEnumerator. Although SZArrayEnumerator and IEnumerator&lt;T&gt; both implement IEnumerator, they are different types and cannot cast implicitly to each other.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul J</title>
		<link>http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/comment-page-1/#comment-824</link>
		<dc:creator>Paul J</dc:creator>
		<pubDate>Mon, 15 Mar 2010 00:16:10 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/#comment-824</guid>
		<description>Was the follow-up post ever published? I don&#039;t see it, but I&#039;d like to know what you had in mind, if it wasn&#039;t what (the other) Paul said.</description>
		<content:encoded><![CDATA[<p>Was the follow-up post ever published? I don&#8217;t see it, but I&#8217;d like to know what you had in mind, if it wasn&#8217;t what (the other) Paul said.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Igor Ostrovsky</title>
		<link>http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/comment-page-1/#comment-454</link>
		<dc:creator>Igor Ostrovsky</dc:creator>
		<pubDate>Fri, 13 Feb 2009 20:40:23 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/#comment-454</guid>
		<description>@Paul: Yeah, the comment system is very frustrating. I need to find a good comment plugin.

You make an interesting point. I did not try casting the non-genetic enumerator to a generic one, but I am actually mildly surprised that you will get a cast exception.

Igor
PS.: A follow-up post is coming (haven&#039;t gotten around to it yet).</description>
		<content:encoded><![CDATA[<p>@Paul: Yeah, the comment system is very frustrating. I need to find a good comment plugin.</p>
<p>You make an interesting point. I did not try casting the non-genetic enumerator to a generic one, but I am actually mildly surprised that you will get a cast exception.</p>
<p>Igor<br />
PS.: A follow-up post is coming (haven&#8217;t gotten around to it yet).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/comment-page-1/#comment-450</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Thu, 05 Feb 2009 18:17:29 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/#comment-450</guid>
		<description>&lt;grumble&gt;  cut-and-paste bites me again, sorry for the duplicate

A simple cast: 

IEnumerator&lt;int&gt; e = (IEnumerator&lt;int&gt;)arr.GetEnumerator();
or
IEnumerator&lt;int&gt; e = arr.GetEnumerator() as IEnumerator&lt;int&gt;;

won’t have the desired effect. The former will throw a cast exception and the latter will result in e being null.

It should first be converted to Enumerable and then get the Enumerator:

IEnumerator&lt;int&gt; e = arr.AsEnumerable&lt;int&gt;().GetEnumerator();

And now I’m hoping that this is wrong and there’s an easier way, because that’s damned ugly when you think about it …</description>
		<content:encoded><![CDATA[<p>&lt;grumble&gt;  cut-and-paste bites me again, sorry for the duplicate</p>
<p>A simple cast: </p>
<p>IEnumerator&lt;int&gt; e = (IEnumerator&lt;int&gt;)arr.GetEnumerator();<br />
or<br />
IEnumerator&lt;int&gt; e = arr.GetEnumerator() as IEnumerator&lt;int&gt;;</p>
<p>won’t have the desired effect. The former will throw a cast exception and the latter will result in e being null.</p>
<p>It should first be converted to Enumerable and then get the Enumerator:</p>
<p>IEnumerator&lt;int&gt; e = arr.AsEnumerable&lt;int&gt;().GetEnumerator();</p>
<p>And now I’m hoping that this is wrong and there’s an easier way, because that’s damned ugly when you think about it …</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/comment-page-1/#comment-449</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Thu, 05 Feb 2009 18:14:34 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/#comment-449</guid>
		<description>A simple cast:

            IEnumerator e = (IEnumerator)arr.GetEnumerator();
or
            IEnumerator e = arr.GetEnumerator() as IEnumerator;

won&#039;t have the desired effect.  The former will throw a cast exception and the latter will result in e being null.

It should first be converted to Enumerable and then get the Enumerator:

             IEnumerator e = arr.AsEnumerable().GetEnumerator();

And now I&#039;m hoping that this is wrong and there&#039;s an easier way, because that&#039;s damned ugly when you think about it ...</description>
		<content:encoded><![CDATA[<p>A simple cast:</p>
<p>            IEnumerator e = (IEnumerator)arr.GetEnumerator();<br />
or<br />
            IEnumerator e = arr.GetEnumerator() as IEnumerator;</p>
<p>won&#8217;t have the desired effect.  The former will throw a cast exception and the latter will result in e being null.</p>
<p>It should first be converted to Enumerable and then get the Enumerator:</p>
<p>             IEnumerator e = arr.AsEnumerable().GetEnumerator();</p>
<p>And now I&#8217;m hoping that this is wrong and there&#8217;s an easier way, because that&#8217;s damned ugly when you think about it &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/comment-page-1/#comment-442</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Tue, 03 Feb 2009 15:51:22 +0000</pubDate>
		<guid isPermaLink="false">http://igoro.com/archive/puzzling-over-arrays-and-enumerators-in-c/#comment-442</guid>
		<description>You get this error:

Cannot implicitly convert type &#039;System.Collections.IEnumerator&#039; to &#039;System.Collections.Generic.IEnumerator&lt;T&gt;&#039;.

To make the code compilable you need to create a cast:

IEnumerator&lt;T&gt; e = (IEnumerator&lt;T&gt;) arr.GetEnumerator();

or safe cast:

IEnumerator&lt;T&gt; e = arr.GetEnumerator() as IEnumerator&lt;T&gt;</description>
		<content:encoded><![CDATA[<p>You get this error:</p>
<p>Cannot implicitly convert type &#8216;System.Collections.IEnumerator&#8217; to &#8216;System.Collections.Generic.IEnumerator&lt;T&gt;&#8217;.</p>
<p>To make the code compilable you need to create a cast:</p>
<p>IEnumerator&lt;T&gt; e = (IEnumerator&lt;T&gt;) arr.GetEnumerator();</p>
<p>or safe cast:</p>
<p>IEnumerator&lt;T&gt; e = arr.GetEnumerator() as IEnumerator&lt;T&gt;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
