Re: foreach in two dimensional array in C#

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Bob Grommes (bob_at_bobgrommes.com)
Date: 10/07/04


Date: Thu, 7 Oct 2004 15:37:35 -0700

I think you really need a for loop for this kind of thing. At present, it's
slightly faster than a foreach anyway (not that this probably matters in
this context).

--Bob

"Gopal Krish" <geeksgk@yahoo.com> wrote in message
news:8b4092e6.0410061938.489699f6@posting.google.com...
> Any sample code that uses foreach statement to walkthrough a two
> dimensional array? My requirement is to process data in only one
> dimension (say column 0 in each row of the array)
>
> Example
> menulinks[0,0] = "My Home";
> menulinks[0,1] = "MyHome.aspx";
>
> menulinks[1,0] = "Credit";
> menulinks[1,1] = "Credit.aspx";
>
> menulinks[2,0] = "Debit";
> menulinks[2,1] = "debit.aspx";
>
>
> foreach (string menuitem in menulinks)
> {
> Label1.Text += " " + menuitem
> }
>
> Current Output in Label1.Text
> " My Home MyHome.aspx Cerdit Credit.aspx Debit debit.aspx"
>
> What I needed
> " My Home Cerdit Debit"



Relevant Pages

  • Re: Count Lines in (Huge) Text Files
    ... A few years ago, I was doing some high-throughput disk stuff and my recollection is that I found the same thing you did: larger buffers only helped up to about 8K or so, and past that any improvement was minimal. ... me that with appropriate settings for its buffer, it should perform better, since it ought to be optimized for line-based i/o. ... Assuming what's hurting you in the explicit forloop is the retrieval of the data and not the counter increment, the above should perform basically as well as a plain foreach() loop. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: a question about for and foreach
    ... foreach (@array) { ... why @array are changed after this foreach loop!!! ... The "foreach" loop iterates over a normal list value and sets the ... If any element of LIST is an lvalue, you can modify it by modifying ...
    (perl.beginners)
  • Re: Lost data on socket - Can we start over politely?
    ... $clsel as a single-element-holding object containing the current ... simply performing the following check on $sel instead of $clsel? ... removing elements from something from a list used for the loop is a Bad ... Doesn't that throw the foreach() loop out of sync? ...
    (comp.lang.perl.misc)
  • Re: foreach statement output
    ... > I'm still trying to get an understanding of the way a foreach loop loops. ... You can't use the loop variable as an index to your array. ...
    (comp.infosystems.www.authoring.cgi)
  • Re: array and hash patter matching
    ... however I am struggling on how to compare the hash with an array for any ... Why are you using this foreach loop inside the while loop? ... client_list is a list of one or more host names, host addresses, ...
    (perl.beginners)