Next generation's garbage RSS 2.0
# Friday, September 04, 2009

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.

public static class ExtensionMethods
{
    public static IEnumerable<T> UnionAll<T>(this IEnumerable<IEnumerable<T>> eet)
    {
        foreach (var et in eet)
            foreach (var t in et)
                yield return t;
    }
}

Friday, September 04, 2009 4:16:24 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
LINQ
Archive
<September 2009>
SunMonTueWedThuFriSat
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
All Content © 2010, Hafthor Stefansson - Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way. - Sign In