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

VulpesRank #55 · 29.2K reputationPosted Jul 11, 2012, 2:27 AM EDT
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:
Duane68 reputationPosted Jul 11, 2012, 8:53 AM EDT
Duane68 reputationPosted Jul 12, 2012, 6:42 PM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 13, 2012, 1:48 AM EDT