如何获得物品的循环 [英] How to get for loop through the items
本文介绍了如何获得物品的循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
例如,我有两个数据集,其中第一个数据集有2个项,即item1,item2,第二个数据集有3个项,即item3,item4,item5.
我想将这些项目的结果计算为以下组合:
item1和item2
item2和item3
item3和item4
item4和item5
Hello All,
For example I have two data sets in which first dataset have 2 items namely item1,item2 and second dataset have 3 items namely item3,item4,item5.
I want to calculate result from these items as the following combination:
item1 and item2
item2 and item3
item3 and item4
item4 and item5
how for loop is executed for the above mentioned process?
推荐答案
嘿,您可以创建对象的通用列表.循环浏览两个结果集并将它们添加到列表中.假设您的商品是一个字符串:
Hey, you can create a generic list of your objects. Loop through both result sets and add them to the list. Let''s assume your items are a string :
List<string> myItems = new List<string>();
foreach (string firstListItem in firstCollection)
{
myItems.Add(firstListItem)
}
foreach (string secondListItem in secondCollection)
{
myItems.Add(secondListItem);
}
</string></string>
然后遍历整个结果并计算您想要的任何结果:
Then loop trough the entire result and calculate whatever you want :
for (int i = 1; i < myItems.Count; i++)
{
// Do something with myItems[i-1] and myItems[i]
}
祝你好运!
爱德华
Good luck!
Eduard
如果我理解正确的话?
简单的方法但不是最优化
1)
创建新的数据表.
3)添加来自table1和table2的所有数据
4)排序新的数据表
5)
indx列
[0] A
[1] b
[2] c
[3] d
[4] e
[5] f
[6] g
[7] h
求和循环
i = 0; i <= 7; i ++
sum [0] = newable [i] + newtable [i + 1];
i = i +1;
所以总和将被填充4次.
if i understand correctly?
Simple way but not optimizd
1)
Create new data table.
3) Add all data from table1 and table2
4) sort new datatable
5)
indx column
[0] A
[1] b
[2] c
[3] d
[4] e
[5] f
[6] g
[7] h
loop for sum
i=0;i<=7; i++
sum[0] = newable[i]+newtable[i+1];
i =i +1;
so sum will populated 4 time.
这篇关于如何获得物品的循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文