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
Comments are closed.
Archive
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
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