[分享]VB.NET 2010输出一维数组、二维数组的方法 (新手)
程序代码:
Public Class Form1 Dim array1 As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9} '一维数组变量 Dim array2 As String(,) = {{1, 2, 3, 1, 2, 3}, {4, 5, 6, 4, 5, 6}} '二维数组变量 '输出一维数组的元素 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer For i = 0 To array1.Length - 1 '根据数组中的元素数量循环 RichTextBox1.Text = RichTextBox1.Text & array1(i) & vbCrLf '输出到RichTextBox1 Next End Sub '输出二维数组的元素 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim i, j As Integer For i = 0 To array2.Rank - 1 '根据数组的维数循环 For j = 0 To array2.Length / array2.Rank - 1 '根据维数中的元素数量循环 RichTextBox1.Text = RichTextBox1.Text & array2(i, j) & vbCrLf '输出到RichTextBox1 Next Next End Sub End Class