简体   繁体   English

嵌套泛型类型的扩展方法

[英]Extension method for nested generic type

I'm writing an extension method, that should work on a generic of generics, say IEnumerable<IEnumerable<T>> - for example 我正在编写一个扩展方法,该方法应该适用于泛型的泛型,例如IEnumerable<IEnumerable<T>> -

public static IEnumerable<T> SelectAll<T>(this IEnumerable<IEnumerable<T>> source)
{
    return source.SelectMany(x => x);
}

Now, how do I make it accept a parameter that's actually a List<List<T> ? 现在,如何使它接受实际上是List<List<T> I've only been able to make it swallow a List<IEnumerable<T>> , is there a way without manually casting to that? 我只能使它吞下List<IEnumerable<T>> ,有没有一种方法可以不手动强制转换为它?

It's working nicely, what's the problem you're having? 运行正常,您遇到了什么问题?

var w = new List<List<int>>(){
    new List<int>{2,3,4},
    new List<int>{5,3,2}
};

w.SelectAll().Dump();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM