0

Hi, I have array1 and array2.
I need to compare this two array. The number in array1 which is same in array2, it would not come out any output.
If the number in array1 is different with the number in array2, then it will show out the number.
Now my problem is it just will compare the 1st number in the array1 only and cant compare the second number .
is that my for loop got problem?
My coding are shown below.
Hope someone can help me .

try
{

String[] myArray = new string[richTextBox1.Lines.Length];
int i = 0;
foreach (string doub in sortList.Keys)
{
myArray = doub;
i++;
}

String[] myArray1 = new string[richTextBox2.Lines.Length];
int j = 0;
foreach (string doub1 in sortList1.Keys)
{
myArray1[j] = doub1;
j++;
}


String[] array1 = new string[richTextBox4.Lines.Length];
String[] array2 = new string[richTextBox5.Lines.Length];

String array3 = "";

for (int k = 0; k < myArray.Length; k++)
{
array1[k] = myArray[k];

}
for (int n = 0; n < myArray1.Length; n++)
{
array2[n] = myArray1[n];

}

for (int k = 0; k < array1.Length; k++)
{

for (int n = 0; n < array2.Length; n++)
{

if (!array1[k].Contains(array2[n]))
{

array3 += array1[k] + ":" + array2[n] + " \n ";

}
else
{

}
richTextBox3.AppendText(array3);
}

}

}

catch(Exception)
{
MessageBox.Show("Please Click Again!");
}

}

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by ashley11
0

Check out this code for comparing two arrays:

int[] array1 = { 1, 2, 3, 4, 5, 6 };
            int[] array2 = { 1, 3, 4, 4, 5, 7 };

            int[] newArray = null;
            int k = 1;
            for (int i = 0; i < array1.Length; i++)
            {
                if (array1[i] != array2[i])
                {
                    Array.Resize(ref newArray, k);
                    newArray[k - 1] = array1[i];
                    k++;
                }
            }

Mitja

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.