0

how I can compare each row of 2D array with 1d array in order to insert 1D array if it is not found in 2D array if my 2d array is like {{3,7,9},{1y ,8,6}} and my 1d array for example {3,7,9},how I can know if it's already there ,my code below insert 1d array at a time to 2d array ,I tried to use .equal but it doesn't work

    Private Sub Add_Item_Array_2D2(ByRef Array_2D As Double(,), ByVal d As Integer,
                        ByVal Items As Double())
    Dim tmp_array(Array_2D.GetUpperBound(0) + d, Array_2D.GetUpperBound(d)) As Double

    For n As Integer = 0 To Array_2D.GetUpperBound(0)
        For m = 0 To Array_2D.GetUpperBound(1)
            Dim pp = (Array_2D(n, m)).Equals(Items)
            If pp = False Then

                For x As Integer = 0 To Array_2D.GetUpperBound(0)
                    For k = 0 To Array_2D.GetUpperBound(1)

                        tmp_array(x, k) = Array_2D(x, k)
                    Next
                Next
                For j = 0 To Items.Count - 1


                    tmp_array(tmp_array.GetUpperBound(0), j) = Items(j)

                Next
                Array_2D = tmp_array


            End If

        Next
    Next

End Sub

1 Answer 1

1

How to find out whether a row in your 2D array equals your 1D array:

Compare bounds. If the column count of your 2D array is unequal 
to the length of your 1D array, throw an error.

Loop through the rows of the 2D array:
    If, for all column indexes, 2D(row, column) = 1D(column):
        return Success

return Failure

Translating this algorithm to VB.NET is left as an exercise. Hint: For the for all part, Enumerable.Range and Enumerable.All might be helpful.

Sign up to request clarification or add additional context in comments.

1 Comment

the first suggestion I tried it before ,but I will try Enumerable.Range

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.