1

i've a list collection which looks like

myList[0].innerList[0 to 50]
myList[1].innerList[51  to 100]
myList[2].innerList[101 to 120]

the myList can go as per the size, at max there are 50 objects in the innerList. I get the innerList as a response from an API where the page size is set to 50.

i want my new list to have all these 0 - 120 objects in a single list like

newList[0 to 120]

i'm trying using LINQ like this

var newList = from reg in myList
           select reg.innerList.ToList();

But i get

newList[0].[0 to 50]
newList[1].[51 to 100]

Can anyone help me with the LINQ ?

1
  • you want to copy the items of one list to second list? Commented Mar 31, 2014 at 6:23

2 Answers 2

3

think SelectMany should do the trick.

var newList = myList.SelectMany(x => x.innerList);
Sign up to request clarification or add additional context in comments.

Comments

1

You are nearly there

var newList = (from reg in myList      // for each inner list
               from range in reg       // for each item in each inner list
               select range).ToList();

3 Comments

This too works Ondrej Janacek. Thanks! The selectMany property achieves this in a single line. Hence i'm marking that as an answer.
@Raza I completely understand. I posted the answer just because I felt that it would be beneficial for you to see the query syntax as well (the other one is called lambda syntax). So just for the sense of completeness.
Thank you Ondrej Janacek. Yes your code actually helped me visualize the query syntax. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.