Webb John Webb John - 1 year ago 103
Vb.net Question

Comparing values in a jagged array

What I want to achieve is to compare the index values. arr1val1 and arr2val1, then arr1val2 and arr2val2, then so on and so forth provided that they have the same number of indexes. Lastly a message box that will prompt if a mismatch is detected in any of the compared indexes regardless of how many mismatches. So far I have this code.

Dim str()() As String = _
New String()() {New String() {"arr1val1", "arr1val2"}, New String() {"arr2val1", "arr2val2"}}

For Each arstr As String() In str
For Each strElement As String In arstr


Answer Source

Based on your comment:

Dim mismatchFound = False

For i = 0 To str(0).GetUpperBound(0)
    If str(0)(i) <> str(1)(i) Then
        mismatchFound = True
        Exit For
    End If

The succinct way, i.e. using LINQ:

Dim mismatchFound = Enumerable.Range(0, str(0).Length).
                               Any(Function(i) str(0)(i) <> str(1)(i))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download