Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi all,
I am new to mvc and i have been facing some silly issue may be but i need some help to resolve this simple one..

My prob is for example i am having two list of strings arrays say

string[] products= new string[]{"comp","TV"}
string[] Companies=new string[]{"Google","Microsoft"}

Now i have tables with two table headers say products and companies and I want them to be displayed like below
Product Companies
Comp GOogle
TV Microsoft

Now i need to display like above simulataneously that too dynamically i know we can use foreach loop with (var prod in products)
{
td prod td
}but if i want to update i should use another foreach with companies for looping so please help to solve this issue with a single foreach so to update both arrays of strings in a single time dynamically.
Posted
Updated 29-Dec-16 9:03am
Comments
Sergey Alexandrovich Kryukov 4-Apr-15 17:21pm    
What have you tried so far?
—SA

Quote:
Now i need to display like above simulataneously that too dynamically i know we can use foreach loop with (var prod in products)

The foreach loop is done to handle 1 array/list/collection. In order to handle 2 lists simultaneously, it is easier to use a simple for loop.
 
Share this answer
 
Hello:
I think that the following will work
<br />
@{<br />
  int i=0;<br />
  foreach (var prod in products) {<br />
     var comp=Companies[i];<br />
     ... // use here <var>prod</var> and comp to <var>comp</var> as you need<br />
     i++;<br />
  }<br />
}@<br />
 
Share this answer
 
v2

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