Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I need help with trying to join the contents of two arraylists.

I am filling my sorted arrays with file names and want to end up with the following output in a text file.

Leftfile1,Rightfile1
Leftfile2,Rightfile2
Leftfile3,Rightfile3
Leftfile4,Rightfile4
etc

I have no issue with adding to array or saving to a text file. My problem is creating a loop that takes item1 from first array and then item 1 from second array and makes one string out of them separated by a comma and to keep doing this until end of the array.

Can someone please help

Thanks
J
Posted
Comments
Sergey Alexandrovich Kryukov 24-Feb-15 11:52am    
To start with, don't use that obsolete ArrayList. Use System.Collections.Generic.List<>
This is not even a question. What "problem"?
What have you tried so far?
—SA
johnjsm 24-Feb-15 11:55am    
My problem is trying to join each item in array into a single string.
I've been trying to use a for loop with no result

1 solution

If the count of records in the two array is the same, its easy.

C#
for (int i=0;i<=arrLeft.count;i==)
{
   Console.Writeline(arrLeft[i] + arrRight[i]);
}


If the count is different, then try something like -
C#
int minCount;
if (arrLeft.Length > arrRight)
{
   minCount = arrRight;
}
else
{
   minCount = arrLeft;
}
for (int i=0;i<=minCount;i==)
{
   Console.Writeline(arrLeft[i] + arrRight[i]);
}
 
Share this answer
 
Comments
johnjsm 24-Feb-15 12:07pm    
Any chance you can give it in vb

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