rivate Function AreArraysEqual(Of T)(ByVal a(,) As T, ByVal b(,) As T) As Boolean
If a Is Nothing AndAlso b Is Nothing Then
Return False
End If
If a Is Nothing Or b Is Nothing Then
Return False
End If
For i As Integer = 0 To a.GetUpperBound(0)
For j As Integer = 0 To a.GetUpperBound(1)
If Not a(i, j).Equals(b(i, j)) Then
Return False
End If
Next
Next
Return True
VulpesPosted Jul 13, 2012, 5:48 AM
DuanePosted Jul 12, 2012, 10:42 PM
DuanePosted Jul 11, 2012, 12:53 PM
VulpesPosted Jul 11, 2012, 6:27 AM
However, it will throw an exception if the upper bound of 'b' is less than the upper bound of 'a' when attempting to access b(i,j) for indices which don't exist in that array.
To avoid that you need to check that the upper bounds are equal before iterating through the elements.
Also the first 'If' statement is superfluous since if 'a' and 'b' are Nothing, then certainly 'a' is Nothing. However, the 'Or' operator in the second 'If' statement should be replaced with 'OrElse' to avoid unnecessarily checking that 'b' is Nothing if 'a' is Nothing.
Making these changes, leaves us with the following: