Mix list <string> in C #

I have 4 lists in C #, how can I make a list of them. means to say, make a list from the result of 4 lists.

+3
source share
4 answers

To achieve this, you can also use the List constructor.

Sort of

List<string> list1 = new List<string>();
List<string> list2 = new List<string>();
List<string> list3 = new List<string>();

...

List<string> concat = new List<string> (list1.Concat(list2).Concat(list3));
+3
source

Your question is not very clear, but I suspect you mean something like:

List<List<string>> stringLists = ...;

// SelectMany is a "flattening" operation
List<string> singleList = stringLists.SelectMany(list => list).ToList();
+1
source

Use List.AddRange to add one list to another.

+1
source
List<string> list1 = new List<string>() { "rabbit", "hat" };
List<string> list2 = new List<string>() { "frog", "pond" };
list2.InsertRange(0, list1);
0
source

Source: https://habr.com/ru/post/1766208/


All Articles