這可能讓你開始你會想動態設置「行」和「列」的上限。這將它輸出到一個文本框中,但將變量分配給一個新數組將很容易。
Dim arr(3, 3) As String
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim i As Integer = 1
For row As Integer = 0 To 2
For col As Integer = 0 To 2
arr(row, col) = i
i += 1
Next
Next
End Sub
Public Sub showStraight()
TextBox1.Text = ""
For row As Integer = 0 To 2
Dim line As String = ""
For col As Integer = 0 To 2
line += arr(row, col)
Next
TextBox1.Text += line & vbNewLine
line = ""
Next
End Sub Public Sub showRotated()
TextBox1.Text = ""
For col As Integer = 0 To 2
Dim line As String = ""
For row As Integer = 2 To 0 Step -1
line += arr(row, col)
Next
TextBox1.Text += line & vbNewLine
line = ""
Next
End Sub
你能解釋什麼是旋轉陣列? – Steve
@Steve完成後,將示例放在原始帖子中。 – ace007