473,385 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C# foreach syntax error

How can I do this in one line

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

Thanks
Nov 15 '05 #1
3 6476
You can not.

foreach(string answer in myansList)
{
foreach(string qKey in qKeyList)
{
//do something -- for each answer, iterate all items in qKeyList)
}
}
"Douglas Gage" <ha******@neo.tamu.edu> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
How can I do this in one line

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

Thanks

Nov 15 '05 #2
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
"Douglas Gage" <ha******@neo.tamu.edu> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
How can I do this in one line

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

Thanks

Nov 15 '05 #3
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
mj*****@mj10777.de
"Douglas Gage" <ha******@neo.tamu.edu> schrieb im Newsbeitrag
news:Oy**************@TK2MSFTNGP10.phx.gbl...
How can I do this in one line

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

Thanks

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Niall | last post by:
Ok, maybe this is getting too lazy and too demanding, but hey, I thought I'd see what people thought about it. Would anyone else find a syntax like: foreach (string Name in CompanyNames and...
32
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open...
104
by: cody | last post by:
What about an enhancement of foreach loops which allows a syntax like that: foeach(int i in 1..10) { } // forward foeach(int i in 99..2) { } // backwards foeach(char c in 'a'..'z') { } // chars...
14
by: Josh Ferguson | last post by:
I don't believe a syntax driven equivalent exists for this, but I just thought it would be neat if you could use foreach to do something like this: foreach (Object x in collection1, collection2)...
27
by: Tripper | last post by:
Which is the better way to go and why? //trivial example List<string> strings = GetStrings(); foreach (string s in strings) { // some operation; } strings.ForEach(
2
moishy
by: moishy | last post by:
I have a problem when passing by refrence using FOREACH(): foreach ($array as &$value) {if ($value <= 0) {$value+=12;}} It should have worked,...
10
by: fig000 | last post by:
HI, I'm new to generics. I've written a simple class to which I'm passing a generic list. I'm able to pass the list and even pass the type of the list so I can use it to traverse it. It's a...
3
by: JonB | last post by:
The examples I'm generally finding on the web of how to do nested loops are confusing and extremely scarce. Here's what I'm trying to do... I have an array named $data that I believe qualifies as...
2
by: Jason Ourscene | last post by:
I'm using the simplexml class to parse through some xml. when i use the standard foreach loop syntax, i get the expected results. <?php foreach ($xml->item as $artist) { echo $artist->title "<br...
8
by: Bill Butler | last post by:
"raylopez99" <raylopez99@yahoo.comwrote in message news:bd59f62a-5b54-49e8-9872-ed9aef676049@t54g2000hsg.googlegroups.com... <snip> I don't think "right" is the correct word. There are many...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.