<?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>Fun with yield, generics, and foreach</title><link>http://blogs.msdn.com/b/jmstall/archive/2006/01/30/foreach-trivia.aspx</link><description>We all know that you can use C#'s foreach keyword to iterate through all items in an enumeration. Suppose you have a list of mixed-types: 
 
 object [] list = new object [] {1,2, "abc" , 5f, "def" }; 
 Trying to enumerate through the strings like this</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Links of the Week</title><link>http://blogs.msdn.com/b/jmstall/archive/2006/01/30/foreach-trivia.aspx#581662</link><pubDate>Sun, 23 Apr 2006 19:32:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:581662</guid><dc:creator>Jeff W. Barnes</dc:creator><description>Comparison of AJAX frameworks for ASP.NET &lt;br&gt;Extending CodeSmith merge functionality &lt;br&gt;Good read on SQLCLR...&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=581662" width="1" height="1"&gt;</description></item><item><title>Links of the Week</title><link>http://blogs.msdn.com/b/jmstall/archive/2006/01/30/foreach-trivia.aspx#553171</link><pubDate>Thu, 16 Mar 2006 23:30:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:553171</guid><dc:creator>Jeff Barnes - MCSD</dc:creator><description>Comparison of AJAX frameworks for ASP.NET &lt;br&gt;Extending CodeSmith merge functionality &lt;br&gt;Good read on SQLCLR...&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=553171" width="1" height="1"&gt;</description></item><item><title>Links of the Week</title><link>http://blogs.msdn.com/b/jmstall/archive/2006/01/30/foreach-trivia.aspx#524147</link><pubDate>Fri, 03 Feb 2006 19:37:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:524147</guid><dc:creator>Jeff Barnes - MCSD</dc:creator><description>&lt;br&gt;Comparison of AJAX frameworks for ASP.NET &lt;br&gt;Extending CodeSmith merge functionality &lt;br&gt;Good read on...&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=524147" width="1" height="1"&gt;</description></item><item><title>re: Fun with yield, generics, and foreach</title><link>http://blogs.msdn.com/b/jmstall/archive/2006/01/30/foreach-trivia.aspx#522538</link><pubDate>Thu, 02 Feb 2006 01:14:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:522538</guid><dc:creator>Mihailik</dc:creator><description>I'm sorry my name is not Themes. The browser at my work have wrong cookies :-)&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=522538" width="1" height="1"&gt;</description></item><item><title>re: Fun with yield, generics, and foreach</title><link>http://blogs.msdn.com/b/jmstall/archive/2006/01/30/foreach-trivia.aspx#522534</link><pubDate>Thu, 02 Feb 2006 01:12:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:522534</guid><dc:creator>Mihailik</dc:creator><description>Sure, my mistake.&lt;br/&gt;&lt;br/&gt;I saw that ForEach method in Array and List&amp;lt;T&amp;gt;, but it seems ForEach is absent in Linq at this time. Interestingly why...&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=522534" width="1" height="1"&gt;</description></item><item><title>re: Fun with yield, generics, and foreach</title><link>http://blogs.msdn.com/b/jmstall/archive/2006/01/30/foreach-trivia.aspx#520891</link><pubDate>Tue, 31 Jan 2006 21:57:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:520891</guid><dc:creator>Abhinaba Basu [MSFT]</dc:creator><description>Themes thanks for the nice pointer. However, I was not able to find a pre-defined predicate in System.Query so I cooked up the following&lt;br/&gt;&lt;br/&gt;object[] list = { 1, 2, &amp;quot;abhinaba&amp;quot;, 5f, &amp;quot;basu&amp;quot; }; &lt;br/&gt;list.Where(x =&amp;gt; x is string).ForEach=(Console.WriteLine);&lt;br/&gt;&lt;br/&gt;For ForEach I created my own Extension method&lt;br/&gt;&lt;br/&gt;static class MyExtensions&lt;br/&gt;{&lt;br/&gt;    public static void ForEach&amp;lt;T&amp;gt;(this IEnumerable&amp;lt;T&amp;gt; list, Action&amp;lt;T&amp;gt; act)&lt;br/&gt;    {&lt;br/&gt;        foreach (T t in list)&lt;br/&gt;            act(t);&lt;br/&gt;    }&lt;br/&gt;}&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=520891" width="1" height="1"&gt;</description></item><item><title>Interesting Finds</title><link>http://blogs.msdn.com/b/jmstall/archive/2006/01/30/foreach-trivia.aspx#520781</link><pubDate>Tue, 31 Jan 2006 20:13:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:520781</guid><dc:creator>Jason Haley</dc:creator><description>&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=520781" width="1" height="1"&gt;</description></item><item><title>re: Fun with yield, generics, and foreach</title><link>http://blogs.msdn.com/b/jmstall/archive/2006/01/30/foreach-trivia.aspx#520703</link><pubDate>Tue, 31 Jan 2006 19:02:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:520703</guid><dc:creator>Mike Stall - MSFT</dc:creator><description>Those are some nice examples.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=520703" width="1" height="1"&gt;</description></item><item><title>Interesting Finds</title><link>http://blogs.msdn.com/b/jmstall/archive/2006/01/30/foreach-trivia.aspx#520557</link><pubDate>Tue, 31 Jan 2006 16:38:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:520557</guid><dc:creator>Jason Haley</dc:creator><description>&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=520557" width="1" height="1"&gt;</description></item><item><title>re: Fun with yield, generics, and foreach</title><link>http://blogs.msdn.com/b/jmstall/archive/2006/01/30/foreach-trivia.aspx#520401</link><pubDate>Tue, 31 Jan 2006 13:15:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:520401</guid><dc:creator>Themes</dc:creator><description>Abhinaba, Console.WriteLine can be used as Action&amp;lt;string&amp;gt;. This makes you code even simpler:&lt;br/&gt;&lt;br/&gt;list.Where(...).ForEach(Console.WriteLine);&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=520401" width="1" height="1"&gt;</description></item></channel></rss>