Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have two lists - list1 and list2. i want to concatinate list 1 item + list 2 item and save to txt file.below code is not working how we can loop parellely?

sample output

List1
........
 
hello
hai
 
 
List1
........
bro
joy


expecting-hello bro,hai joy

What I have tried:

C#
foreach (string code in List1)

                {



                for (int i = 0; i < List2.Count; i++)

                {

                    if (code != "")

                    {



                        string total = code + ", " + "'" + List2[i] + "')";

                        fullcode.Add(total);





                    }



                }



                }
Posted
Updated 12-May-22 12:46pm
v2

1 solution

C#
string result = "";
for (int i = 0; i < List1.Length; i++)
{
    string temp = List1[i] + " " + List2[i];
    result += temp + ", ";
}
 
Share this answer
 

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