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
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
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