# 求任意数组的交集解决思路

www.myexceptions.net  网友分享于：2013-12-30  浏览：66次

int[]   a1={1,2,3,4,5,6,7}
int[]   a2={2,3,4,5,6,7,9}
int[]   a3={2,3,4,5,6,8,9}
int[]   a4={1,2,4,5,6,8,9}

2,4,5,6

------解决方案--------------------

------解决方案--------------------
int[] a1 ={ 1, 2, 3, 4, 5, 6, 7 };
int[] a2 ={ 2, 3, 4, 5, 6, 7, 9 };
int[] a3 ={ 2, 3, 4, 5, 6, 8, 9 };
int[] a4 ={ 1, 2, 4, 5, 6, 8, 9 };
foreach (int w in a1)
{
foreach (int x in a2)
{
foreach (int y in a3)
{
foreach (int z in a4)
{
if ((z == y) && (y == x) && (x == w))
{
Console.WriteLine(z);
}
}
}
}
}
------解决方案--------------------

ArrayList al = new ArrayList();
foreach(int ivalue in a1)
{
bool bexist = false;
for(int i=1;i <N;i++)
{
int[] ary = GetArray(i);
if(ary.IndexOf(ivalue) > -1) bexist = true;
}
}
return al;
------解决方案--------------------

------解决方案--------------------

------解决方案--------------------
int[] a1={1,2,3,4,5,6,7};
int[] a2={2,3,4,5,6,7,9};
int[] a3={2,3,4,5,6,8,9};
int[] a4={1,2,4,5,6,8,9};

List <int> l1 = new List <int> (a1);
List <int> l2 = new List <int> (a2);
List <int> l3 = new List <int> (a3);
string s = " ";
foreach (int i in a4)
{
if (l1.Contains(i) && l2.Contains(i) && l3.Contains(i))
{
s += i.ToString() + ', ';
}
}
Console.WriteLine(s.Substring(0,s.Length-1));
------解决方案--------------------
ding~~~