简体   繁体   中英

LINQ IEnumerable<T[]> to IEnumerable<T>

If a query returns IEnumerable, how can I make it flat and have all the T from the arrays in a single IEnumerable?

var types = from genericType in subscriber.GetType().GetInterfaces()
            where genericType.IsGenericType 
            && genericType.GetGenericTypeDefinition() == typeof (ISubscriber<>)
            select genericType.GetGenericArguments();

您可以从Linq使用SelectMany方法:

var flat = types.SelectMany(x => x);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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