Click here to Skip to main content
15,904,655 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 31-Mar-11 4:47am
v2
Comments
[no name] 31-Mar-11 10:32am    
Where is the data coming from and why do you need two datasets?
#realJSOP 31-Mar-11 10:33am    
What have you tried?
Sandeep Mewara 31-Mar-11 10:34am    
It can be done in a single loop too, but why do you need it and where from such scenario came?
wizardzz 31-Mar-11 10:44am    
Sounds like HW.
[no name] 31-Mar-11 10:48am    
Post your error or Code so that we can guide you to sort the issue.

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 :
C#
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 :
C#
for (int i = 1; i < myItems.Count; i++)
{
  // Do something with myItems[i-1] and myItems[i]
}


Good luck!
Eduard
 
Share this answer
 
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.
 
Share this answer
 

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