多Dim数组+可以循环结构 [英] Multi Dim arrays + is it possible to loop through structures

查看:108
本文介绍了多Dim数组+可以循环结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想创建一个3x8数组,我应该使用下面的数组列表或方法吗?我想我的问题是哪一个更容易处理?



还可以迭代思考结构吗?一个有24(3X8)项的结构?请举例如下







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}}





'通过我的3x8阵列迭代

索引0 = 0至numbers.GetUpperBound( 0)

for index1 = 0 to numbers.GetUpperBound(1)



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



下一页

下一步

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

推荐答案

是,你可以 - 但是看起来很讨厌...

Yes, you can - but it's nasty to look at...
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.


这篇关于多Dim数组+可以循环结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆