TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Combining list of list as a single list
Tapan Patel
Aug 01
2016
Code
665
0
2
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
List<
int
>[] a =
new
List<
int
>[10];
for
(
int
i = 0; i <10; i++)
{
a[i] =
new
List<
int
>();
for
(
int
ji = 0; ji < 5; ji++)
{
a[i].Add(ji * i);
// adding some random int values to each list.
}
}
List<
int
> x = a.SelectMany(i => i.Select(j => j)).ToList();
a is a list of list of integers and by nested for loops I am creating list of list of integers. And whenever we required, by doing selectmany (Lambda), we can combine the list together.
c#
List