0

关于如何遍历两个列表并将各自的条目添加到一行中的任何建议?

以下代码说“stri”无法识别

sw.WriteLine("List of 2D screen space drag points where user dragged object");
    for each(str in startObjDragPosList && stri in deleteObjectList)
    {

        sw.WriteLine("[" + str+ "] was dragged:[" + stri + "] ");
        //separator for later analysis is $
        iDragPoint++;
    }

我知道我可能需要计算这两个列表,但这应该是直截了当的。最好的,

4

2 回答 2

0

一些伪代码,未经测试:

foreach(str in list1) {
    foreach(stri in list2) {
        sw.WriteLine(str + ": " + stri);
    }
}

如果您有两个列表:

list1 = { "1", "2" };
list2 = { "A", "B" };

该循环应该为您提供输出:

1: A
1: B
2: A
2: B

那是你要找的吗?

于 2013-10-16T15:36:13.400 回答
0

通过这样做解决

if(trackPole1NameList.Count == trackPole2NameList.Count)
    {
        for(var o = 0;o<trackPole1NameList.Count;o++)
        {

            //sw.WriteLine("Pole1[" + o + trackPole1NameList[o] + "] Pole2: [" + trackPole2NameList[o] + "]");
            sw.WriteLine("Pole1[" + trackPole1NameList[o] + "] Pole2: [" + trackPole2NameList[o] + "]");
            //sw.WriteLine(o);
        }
    }
于 2013-10-21T07:40:11.120 回答