簡體   English   中英

LINQ IEnumerable <T[]> 到IEnumerable <T>

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

如果查詢返回IEnumerable,如何使它變平並使所有T都在單個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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM