如何比较整个多维数组?- WinForms VB.NET



如何在WinForms VB.NET中比较两个完整的多维数组?

我的代码是检查是否一些Sub将改变数组的内容。

为了做到这一点,它在 sub执行之前生成原始数组的复本。这个复写本在潜艇发生之前不会被碰过。一旦它完成了Sub,我想看看主数组中是否有任何东西改变了。下面是我当前的代码:

If possible = "not possible" Then 'If grid is full
        'Check whether something can be done at all
        For x = 0 To 5
            For y = 0 To 5
                copyarray(x, y) = bigarray(x, y)
            Next
        Next
        Dim movementarray() As String = {"up", "down", "left", "right"}
        For i = 0 To 3
            direction = movementarray(i)
            moveblocks()
        Next
        If copyarray = bigarray Then
            'This throws an error
        End If
End If

注意:copyarraybigarray的复本;moveblocks()Sub,我想看看它是否改变了什么;possible只是运行此代码的先决条件。

我该怎么做?我问这个问题是因为Visual Basic抛出了关于最后一个If语句的以下错误:

错误1:对于"二维整型数组"one_answers"二维整型数组"类型没有定义运算符"="。使用'Is'运算符比较两个引用类型。My GameForm1.vb Line 282 Character 16 My Program

好了,我解决了。这是我的解决方案:

Private Function whatever() as Boolean
    If possible = "not possible" Then 'If grid is full
        'Check whether something can be done at all
        For x = 0 To 5
            For y = 0 To 5
                copyarray(x, y) = bigarray(x, y)
            Next
        Next
        Dim movementarray() As String = {"up", "down", "left", "right"}
        For i = 0 To 3
            direction = movementarray(i)
            moveblocks()
        Next
        Dim changed as Boolean = False
        For i = 0 to 5
            For j = 0 to 5
                If Not copyarray(i, j) = bigarray(i, j) Then Return True : Exit Function
            Next
        Next
    Return False
    End If
    Return False
End Function

相关内容

  • 没有找到相关文章

最新更新