<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr</title>
<link>http://snipplr.com/tags/enumerate</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Mon, 20 May 2013 10:18:44 GMT</pubDate>
<item>
<title>(C#) Enumerate all controls and sub-controls in a windows form - pckujawa</title>
<link>http://snipplr.com/view/27564/enumerate-all-controls-and-subcontrols-in-a-windows-form/</link>
<description><![CDATA[ <p>Found in the above URL. Requires extension methods (C# 3.0+).</p> ]]></description>
<pubDate>Tue, 02 Feb 2010 11:03:02 GMT</pubDate>
<guid>http://snipplr.com/view/27564/enumerate-all-controls-and-subcontrols-in-a-windows-form/</guid>
</item>
<item>
<title>(Python) Index/Element #'s for list - dorseye</title>
<link>http://snipplr.com/view/18498/indexelement-s-for-list/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Wed, 19 Aug 2009 00:19:56 GMT</pubDate>
<guid>http://snipplr.com/view/18498/indexelement-s-for-list/</guid>
</item>
<item>
<title>(C#) Create IEnumerable&amp;amp;lt;string&amp;amp;gt; to manually enumerate over string values - pckujawa</title>
<link>http://snipplr.com/view/11153/create-ienumerableltstringgt-to-manually-enumerate-over-string-values/</link>
<description><![CDATA[ <p>Ever need to enumerate over a collection of strings? Simple, just `foreach(string str in stringContainer)` and you've got them, right? Well, what if you want to enumerate over them manually? Basically, you can't (as far as I've found). You can do `stringContainer.GetEnumerator()`, but that returns a System.Collections.IEnumerator, which holds objects, not strings (thus requiring an explicit cast to get the string value). That is, you cannot do  
    `IEnumerator en = stringContainer.GetEnumerator();  
    en.MoveNext();  
    string myString = en.Current;`  
You have to do  
    `string myString = Convert.ToString(en.Current);`

I don't know why C# doesn't have this built in, but it doesn't (and trying to cast to IEnumerator&amp;lt;string&amp;gt; throws an exception). So, there are a lot of homegrown solutions out there, but this one is the easiest for my application. I needed to read in values from a file and assign them to string variables. Since there are a lot of variables, and their order is sometimes changed between versions, it is a pain to assign each variable by its array index (the array being created by reading in each line and splitting it with a comma). It is much easier to change the ordering of variables by simply moving the line up or down in the source code. Thus the need for an enumerator and my dilemma.

The URL refers to similar code from an O'Reilly book.

The 'yield return' statement essentially returns one value from a collection each time a value is needed (such as in a foreach or enum.MoveNext), but keeps track of ordering for you. Pretty slick. Google it for more info.</p> ]]></description>
<pubDate>Tue, 13 Jan 2009 19:04:35 GMT</pubDate>
<guid>http://snipplr.com/view/11153/create-ienumerableltstringgt-to-manually-enumerate-over-string-values/</guid>
</item>
<item>
<title>(Other) div with id and class - stavelin</title>
<link>http://snipplr.com/view/8124/div-with-id-and-class/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 01 Sep 2008 10:52:59 GMT</pubDate>
<guid>http://snipplr.com/view/8124/div-with-id-and-class/</guid>
</item>
<item>
<title>(Other) insert slick div - stavelin</title>
<link>http://snipplr.com/view/8122/insert-slick-div/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 01 Sep 2008 10:47:50 GMT</pubDate>
<guid>http://snipplr.com/view/8122/insert-slick-div/</guid>
</item>
<item>
<title>(LaTeX) Numerating lists with letters - Tank</title>
<link>http://snipplr.com/view/5641/numerating-lists-with-letters/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 01 Apr 2008 00:59:45 GMT</pubDate>
<guid>http://snipplr.com/view/5641/numerating-lists-with-letters/</guid>
</item>
</channel>
</rss>