C# foreach syntax error

  • Thread starter Thread starter Douglas Gage
  • Start date Start date
D

Douglas Gage

How can I do this in one line

foreach((string answer in myansList) && (string qKey in qKeyList))
{
//do something
}

Thanks
 
You can not.

foreach(string answer in myansList)
{
foreach(string qKey in qKeyList)
{
//do something -- for each answer, iterate all items in qKeyList)
}
}
 
Depending on what you are trying to do, either nest the second one within
the first one...or fire them seperately. If you had 10 items in each and
you nested them, you'd have 100 iterations which, if that's what you want by
the && than will work. Otherwise split them out.

HTH,

Bill
 
I don't think you can because you are using two conditions, but only one
condition is supported.
Use two foreach loops.

Mark Johnson, Berlin Germany
(e-mail address removed)
 
Back
Top