int[] a = new int[] { 1, 2, 3, 4 };
int[] b = new int[] { 5, 6, 1, 2, 7, 8 };
int Count = 0;
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < b.Length; j++)
{
if (a[i] == b[j])
{
Count++;
break;
}
}
}
Console.WriteLine(Count);
Console.ReadLine();
Above is a simple program which can search through both arrays and find duplicates between them. However I am having difficulty when making the first array a 2D array as I get an error running the code below 'Index was outside the bounds of the array.' I really can't figure out what to do so I would be grateful for any help.
int[][] a = {new int[] { 1, 2, 3, 4 }, new int[] { 3, 9, 9 }};
int[] b = new int[] { 5, 6, 1, 2, 7, 8 };
int Count = 0;
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < b.Length; j++)
{
if (b[j] == a[i][j])
{
Count++;
break;
}
}
}
Console.WriteLine(Count);
Console.ReadLine();
Enumerable.Intersect<TSource>a[i]th array length isa[i].Length, notb.Length. PS: I like your nickname