3

i have a 4 list in c# how i can make a list from them. means to say make a list from the result of 4 list.

1
  • Do you want them just concatenated together? The union avoiding duplicates? The intersection of common elements of the 4 lists? We need more details in order to provide meaningful answers.
    – Pete
    Sep 23, 2010 at 12:27

4 Answers 4

3

You can also use the List constructor to achieve this.

Something like

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));
1

Your question isn't 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

Use List.AddRange to add one list to another.

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

Your Answer

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