static void Main(string[] args)
{
int[] a = new int[] { 2, 4, 5, 7, 8 };
int[] b = new int[] { 9, 4, 5, 6, 7, 8 };
//不要用数组 老出错
ArrayList alist = new ArrayList(a);
ArrayList blist = new ArrayList(b);
ArrayList same = new ArrayList();
ArrayList aDif = new ArrayList();
ArrayList bDif = new ArrayList();
foreach(object o in alist)
{
if (blist.Contains(o))
{
same.Add(o);
}
else {
aDif.Add(o);
}
}
foreach (object o in blist)
{
if (!same.Contains(o))
{
bDif.Add(o);
}
}
Console.WriteLine("相同的");
foreach (Object o in same)
Console.Write(" {0}", o);
Console.WriteLine();
Console.WriteLine("a中特有的");
foreach (Object o in aDif)
Console.Write(" {0}", o);
Console.WriteLine();
Console.WriteLine("b中特有的");
foreach (Object o in bDif)
Console.Write(" {0}", o);
Console.Read();
}
{
int[] a = new int[] { 2, 4, 5, 7, 8 };
int[] b = new int[] { 9, 4, 5, 6, 7, 8 };
//不要用数组 老出错
ArrayList alist = new ArrayList(a);
ArrayList blist = new ArrayList(b);
ArrayList same = new ArrayList();
ArrayList aDif = new ArrayList();
ArrayList bDif = new ArrayList();
foreach(object o in alist)
{
if (blist.Contains(o))
{
same.Add(o);
}
else {
aDif.Add(o);
}
}
foreach (object o in blist)
{
if (!same.Contains(o))
{
bDif.Add(o);
}
}
Console.WriteLine("相同的");
foreach (Object o in same)
Console.Write(" {0}", o);
Console.WriteLine();
Console.WriteLine("a中特有的");
foreach (Object o in aDif)
Console.Write(" {0}", o);
Console.WriteLine();
Console.WriteLine("b中特有的");
foreach (Object o in bDif)
Console.Write(" {0}", o);
Console.Read();
}
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步