本文介绍了如何获得物品的循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
例如,我有两个数据集,其中第一个数据集有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?

推荐答案

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



这篇关于如何获得物品的循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 21:33