帮助arraylists [英] Help with arraylists
问题描述
嗨
我需要帮助才能尝试加入两个arraylists的内容。
我用文件名填充我的排序数组并希望在文本文件中得到以下输出。
Leftfile1,Rightfile1
Leftfile2,Rightfile2
Leftfile3,Rightfile3
Leftfile4,Rightfile4
等
添加到数组或者我没有问题保存到文本文件。我的问题是创建一个循环,从第一个数组中获取item1,然后从第二个数组中获取第1个项,并用逗号分隔它们中的一个字符串并继续执行此操作直到数组结束。
有人可以帮忙吗
谢谢
J
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
推荐答案
如果两个数组中的记录数相同,则很容易。
If the count of records in the two array is the same, its easy.
for (int i=0;i<=arrLeft.count;i==)
{
Console.Writeline(arrLeft[i] + arrRight[i]);
}
如果计数不同,请尝试类似 -
If the count is different, then try something like -
int minCount;
if (arrLeft.Length > arrRight)
{
minCount = arrRight;
}
else
{
minCount = arrLeft;
}
for (int i=0;i<=minCount;i==)
{
Console.Writeline(arrLeft[i] + arrRight[i]);
}
这篇关于帮助arraylists的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!