<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>freachable.net - LINQ</title>
    <link>http://freachable.net/</link>
    <description>Next generation's garbage</description>
    <language>en-us</language>
    <copyright>Hafthor Stefansson</copyright>
    <lastBuildDate>Fri, 04 Sep 2009 23:16:24 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>blog@freachable.net</managingEditor>
    <webMaster>blog@freachable.net</webMaster>
    <item>
      <trackback:ping>http://freachable.net/Trackback.aspx?guid=b73c7a89-6b46-4d33-b8f9-61cdf2308834</trackback:ping>
      <pingback:server>http://freachable.net/pingback.aspx</pingback:server>
      <pingback:target>http://freachable.net/PermaLink,guid,b73c7a89-6b46-4d33-b8f9-61cdf2308834.aspx</pingback:target>
      <dc:creator>Hafthor Stefansson</dc:creator>
      <wfw:comment>http://freachable.net/CommentView,guid,b73c7a89-6b46-4d33-b8f9-61cdf2308834.aspx</wfw:comment>
      <wfw:commentRss>http://freachable.net/SyndicationService.asmx/GetEntryCommentsRss?guid=b73c7a89-6b46-4d33-b8f9-61cdf2308834</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <pre>
          <span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">
            </span>
          </span>
        </pre>
        <p>
Today I was doing some LINQ to objects. I was replacing a pair of nested foreach loops
which built a string list and was looking for an elegant way to do it in LINQ. I ran
into the problem that I needed to convert a list of lists to a single list. The following
extension method works great for that. Works great for merging arrays of arrays without
copying anything.<br /></p>
        <pre>
          <span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">public</span>
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">static</span>
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">class</span> ExtensionMethods
{ <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">static</span> IEnumerable&lt;T&gt;
UnionAll&lt;T&gt;(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">this</span> IEnumerable&lt;IEnumerable&lt;T&gt;&gt;
eet) { <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">foreach</span> (var
et <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">in</span> eet) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">foreach</span> (var
t <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">in</span> et)
yield <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">return</span> t;
} }<br /><br /></span>
        </pre>
        <p>
        </p>
        <img width="0" height="0" src="http://freachable.net/aggbug.ashx?id=b73c7a89-6b46-4d33-b8f9-61cdf2308834" />
      </body>
      <title>UnionAll Extension Method</title>
      <guid isPermaLink="false">http://freachable.net/PermaLink,guid,b73c7a89-6b46-4d33-b8f9-61cdf2308834.aspx</guid>
      <link>http://freachable.net/2009/09/04/UnionAllExtensionMethod.aspx</link>
      <pubDate>Fri, 04 Sep 2009 23:16:24 GMT</pubDate>
      <description>&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Today I was doing some LINQ to objects. I was replacing a pair of nested foreach loops
which built a string list and was looking for an elegant way to do it in LINQ. I ran
into the problem that I needed to convert a list of lists to a single list. The following
extension method works great for that. Works great for merging arrays of arrays without
copying anything.&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; ExtensionMethods
{ &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt;
UnionAll&amp;lt;T&amp;gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt; IEnumerable&amp;lt;IEnumerable&amp;lt;T&amp;gt;&amp;gt;
eet) { &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;foreach&lt;/span&gt; (var
et &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;in&lt;/span&gt; eet) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;foreach&lt;/span&gt; (var
t &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;in&lt;/span&gt; et)
yield &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; t;
} }&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://freachable.net/aggbug.ashx?id=b73c7a89-6b46-4d33-b8f9-61cdf2308834" /&gt;</description>
      <comments>http://freachable.net/CommentView,guid,b73c7a89-6b46-4d33-b8f9-61cdf2308834.aspx</comments>
      <category>LINQ</category>
    </item>
  </channel>
</rss>