LINQ identity function?

后端 未结 7 2162
日久生厌
日久生厌 2020-12-03 16:22

Just a little niggle about LINQ syntax. I\'m flattening an IEnumerable> with SelectMany(x => x).

My problem i

7条回答
  •  难免孤独
    2020-12-03 17:12

    Does this work in the way you want? I realize Jon posted a version of this solution, but he has a second type parameter which is only necessary if the resulting sequence type is different from the source sequence type.

    public static IEnumerable Flatten(this IEnumerable source)
        where T : IEnumerable
    {
        return source.SelectMany(item => item);
    }
    

提交回复
热议问题