0

我将如何将以下输入插入到 2d 数组中,或者如果需要相同效果的不同类型的数组。

  abcd
  efgh
  ijkl

当我单击一个按钮时,我的阵列向右或向左旋转 90 度(如果选择)我已经考虑了大约一个小时我尝试了一些事情但我在 VB.net 上是全新的

使用数字代替的示例:

1 2 3
4 5 6
7 8 9

旋转:

7 4 1
8 5 2
9 6 3

等等

4

1 回答 1

0

这可能会让您入门 您可能希望动态设置“行”和“列”的上限。这会将它输出到一个文本框,但是将变量分配给一个新数组就很容易了。

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
于 2012-11-19T23:50:12.797 回答