简体   繁体   English

使用LINQ,如何转换IList <IList<object> &gt;至IList <object> ?

[英]Using LINQ, how to convert a IList<IList<object>> to IList<object>?

I'm trying to convert a IList<IList<object>> to IList<object> , I mean to have a unique and one list where contains all the element (object) of the first one. 我正在尝试将IList<IList<object>>转换为IList<object> ,我的意思是要有一个唯一的列表,其中包含第一个元素的所有元素(对象)。

    public IList<IList<Page>> PMTs
    {
        get
        {
            var pmts = Processes.Select(x => x.PageMapTable)
                                .ToList();
            return pmts;
        }
    }

    public IList<Page> BlockMapTable
    {
        get
        {
            // Incomplete
            var btm = PMTs.Select(x => x.?? ..
        }
    }

Assuming that you want to flatMap/flatten the list<list<Page>> , you can do that with selectMany method, like so: 假设您要flatMap / flatten list<list<Page>> ,则可以使用selectMany方法执行此操作,如下所示:

public IList<Page> BlockMapTable
{
    get
    {
        var btm = PMTs.SelectMany(x => x).ToList();
    }
}

if you want to read more about it, here is a great blog post about selectMany extension method 如果您想了解更多信息,这是一篇很棒的关于selectMany扩展方法的博客文章。

public IList<Page> BlockMapTable
    {
        get
        {
            return PMTs.SelectMany(p => p).ToList();
        }
    }

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

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