Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
If I want to create a 3x8 array should I do it using array list or method that is below? I guess my question is which one is easier to handle?

Also is it possible to iterate thought a structure? A structure that has 24 (3X8) items in it? Please give example



Dim numbers = {{11, 21, 31}, {12, 22, 32}, {13, 23, 33}, {14, 24, 34}, {15, 25, 35}, {16, 26, 36}, {17, 27, 37}, {18, 28, 38}}


'Iterate through my 3x8 array
For index0 = 0 To numbers.GetUpperBound(0)
For index1 = 0 To numbers.GetUpperBound(1)

Debug.Write(numbers(index0, index1).ToString & " ")

Next
Next
Posted

1 solution

Yes, you can - but it's nasty to look at...
VB
Dim numbers As Integer(,) = New Integer(,) {{11, 21, 31}, {12, 22, 32}, {13, 23, 33}, {14, 24, 34}, {15, 25, 35}, {16, 26, 36}, _
	{17, 27, 37}, {18, 28, 38}}
For Each i As Integer In numbers
	Console.WriteLine(i)
Next
And it's probably better to use two loops.
 
Share this answer
 
Comments
Member 8525993 30-Oct-13 16:08pm    
ok. since it is better to use two loops i will stick to current way. Thanks.
CPallini 30-Oct-13 16:58pm    
Well, I think that's really nasty and unobvious...
Member 8525993 30-Oct-13 17:09pm    
huh? what is the better way of doing it ??
CPallini 30-Oct-13 17:38pm    
I was kidding. However, as Griff noted, using two loops is possibly cleaner.
Member 8525993 31-Oct-13 11:24am    
lol oh got it ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900