Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
Hi,

I have 4 list strings.
How can I add all of them to a list??

Thanks
John
Posted

C#
List<string> lst1 = new List<string>();        
        List<string> lst2 = new List<string>();      
        List<string> lst3 = new List<string>();
        List<string> lst4 = new List<string>();

        List<string> lstFinal  = new List<string>();
        lstFinal.AddRange(lst1);
        lstFinal.AddRange(lst2);
        lstFinal.AddRange(lst3);
        lstFinal.AddRange(lst4);


Reference : Add list data to another list [^]
 
Share this answer
 
v2
C#
List<string> initialList = new List<string>();
// Put whatever you want in the initial list
List<string> listToAdd = new List<string>();
// Put whatever you want in the second list
initialList.AddRange(listToAdd);


Use List.AddRange(collection As IEnumerable(Of T)) method.
It allows you to append at the end of your list another collection/list.
Try this.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900