D
D
Dejsving2019-08-27 18:26:28
C++ / C#
Dejsving, 2019-08-27 18:26:28

How to collect from a variable of type List(List(T)) a variable of type List(T) containing all elements using LINQ?

In the method, it became necessary to create a list from a list of lists with all elements from the parent lists.

Example

Из
List<List<T>>

List<List<int>> list = new List<List<int>>();
for (int i = 0; i < 10; i++)
{
    list.Add(new List<int>());
    for (int j = 0; j < 10; j++)
    {
        list[i].Add(i + j * 10);
    }
}


хочу получить
List<T>

var res = new List<int>();
foreach (var ll in list)
{
    res.AddRange(ll);
}

But at the same time, using LINQ,
I don’t know how to convert ( and ) into < and >, respectively

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2019-08-27
@Dejsving

list.SelectMany( i => i );
Never a c#, but it seems so.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question