473,395 Members | 1,623 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,395 software developers and data experts.

Question about using a FOREACH loop????

If I want to use a FOREACH loop on an array of strings, but didn't want
to include the first member,how would I do this???

Psuedo Code:::

foreach(string a in myStringArray (where a.index>0))
{

some stuff....

}

Aug 1 '06 #1
3 1368
Just keep track if you are on the first one and "continue;"?

Actually, if it is (as you say) a straight array (not an ArrayList,
List<stringor other), then indexer access is very efficient, so you could
just for(int i=1;...) instead of the usual for(int i=0;...).

Anything else is just introducing complexity... to my mind, at least...

Marc
Aug 1 '06 #2
"rhaazy" wrote:
If I want to use a FOREACH loop on an array of strings, but didn't want
to include the first member,how would I do this???

Psuedo Code:::

foreach(string a in myStringArray (where a.index>0))
I don't believe it's possible within the foreach loop syntax. Some
alternate suggestions:

int length = myStringArray.Length;
for (int i = 1; i < length; i++)
{
// do stuff with myStringArray[i]
}

Or:

bool first = true;
foreach(string a in myStringArray)
{
if (first)
first = false;
else
// do stuff
}

--
Timm Martin
Mini-Tools
..NET Components and Windows Software
http://www.mini-tools.com

Aug 1 '06 #3
Thanks for the quick reply, I figured it would have to be done with a
for loop so I quickly switched my method over, but thanks for the help!

Mini-Tools Timm wrote:
"rhaazy" wrote:
If I want to use a FOREACH loop on an array of strings, but didn't want
to include the first member,how would I do this???

Psuedo Code:::

foreach(string a in myStringArray (where a.index>0))

I don't believe it's possible within the foreach loop syntax. Some
alternate suggestions:

int length = myStringArray.Length;
for (int i = 1; i < length; i++)
{
// do stuff with myStringArray[i]
}

Or:

bool first = true;
foreach(string a in myStringArray)
{
if (first)
first = false;
else
// do stuff
}

--
Timm Martin
Mini-Tools
.NET Components and Windows Software
http://www.mini-tools.com
Aug 1 '06 #4

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

Similar topics

7
by: Alex Hopson | last post by:
Hi, I've got a multidimensional array and I can loop through it fine but I can't get the values of first parts of the array - ie: foreach ($a as $v1) { foreach ($v1 as $v2) { echo "$v2\n";...
6
by: h | last post by:
Hi! I have a user control called ListItemControl. This works ok: ListItemControl li = new ListItemControl(); When I iterate with Enumerator through all controls using: IEnumerator e =...
7
by: Madhu Gopinathan | last post by:
Hi, I hope this is the right forum for this question. I am extending ICollection to create a Collection Type (say MyCollection) wherein I can control the types of objects being added to the...
15
by: MuZZy | last post by:
Hi, Consider this: ArrayList al = new ArrayList(); FillList(al); /// NOW TWO SCENARIOS: /// 1. for (int i = 0 ; i < al.Count ; i++)
3
by: Akira | last post by:
I noticed that using foreach is much slower than using for-loop, so I want to change our current code from foreach to for-loop. But I can't figure out how. Could someone help me please? Current...
7
by: Tony Johansson | last post by:
Hello! Why does not this cause a compile error because a ulong has never been implicitly convertible to byte? ulong vektor = {100000,200000,300000}; foreach(byte b in vektor) {...
1
by: greyseal96 | last post by:
Hi, I am a pretty new programmer, so I apologize in andvance if this is a dumb question... In a book that I'm reading to learn C#, it says that when using a foreach() loop, a read-only copy of...
0
by: xrxst32 | last post by:
Hello there, I have some doubts about the best practice for using COM automation, the Runtime Callable Wrapper (RCW) and Marshal.ReleaseComObject. So the question is/are: Do I need to release...
0
by: Tony Johansson | last post by:
Hello! I have the code below. In the previous code not shown below I have used linq to extract some row and these have been placed in the var variable result. In my code there is just one entry...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.