Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

A standard

Dim i As Integer

For Each i In multiDimArray
Next

will do it. I'm not totally sure what order it traverses it

(which dimension increments first in the loop), but I'm sure you

can figure that out.

Posted

Well that is VB code isn't it?

 

The array looks something like this. {{0,0}, {0,1}, {0,2}, {0,3}, {0,4}, {1,0}...........{4,4}

 

 

and it should look like this on the consolewindow:

 

0,0 0,1 0,2 0,3 0,4

1,0 1,1 1,2 1,3 1,4

 

and so on

  • *Experts*
Posted

You know, you can always not use foreach; it may be more

appropriate, in this case, to use a standard for loop.

int i,j;
for (i=0;i<=myArray.GetLength();i++) 
 {
   for (j=0;j<=myArray.GetLength();j++)
   {                              
     // use myArray[i,j] to output the data
   }
 }

  • *Experts*
Posted

Oh. Well, I really don't know what to tell you. foreach can easily

get the data, but I have no idea how to get it out in the order that

you want it. Sorry. :-\

  • *Experts*
Posted

If it's a school assignment shouldn't you be figuring this out on your own? :p

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
Nope no reason why and some friends have made it. Well assignement was a bad word to use, it's more like an excersice and we can use help from other people. There is a big difference between ripping code and getting help.
Posted

Done!

 


int[][] mul;

mul=new int[4][];

mul[0] = new int[5] {0,1,2,3,4};
mul[1] = new int[5] {0,1,2,3,4};
mul[2] = new int[5] {0,1,2,3,4};
mul[3] = new int[5] {0,1,2,3,4};
		
int counter=0;

foreach(int[] j in mul)
{
   foreach(int i in j)
   {
       Console.Write("{0},{1} ",counter,i);
   }
   
   Console.WriteLine();
   counter++;

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...