判断数组重复的不打印出来。帮帮忙

waltguo 2008-12-17 05:00:32
数组a={1,2.3.4.5.6.7},数组b={2,5,4},把b数组中与a不相等的显示出来
怎么写呢 ,我写不出来

using System;
class a
{
static void Main()
{
Foo();

}

public static void Foo()
{
int[] a={1,2,3,4,5,6};
int[] b={3,4,5};

for(int i=0;i<a.Length-1;i++)
{
for(int j=0;j<b.Length-1;j++)
{
if(a[i]==b[j])
break;
Console.WriteLine( a[i]);

}
}
}
}
...全文
47 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
止戈而立 2008-12-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 waltguo 的回复:]
不想用foreach,能不能啊。
[/Quote]

public static void Foo()
{
int[] a={1,2,3,4,5,6};
int[] b={3,4,5};
ArrayList list=new ArrayList(b);
for(int i=0;i<a.Length;i++)
{
if(!list.Contains(a[i]))
{
Console.WriteLine(a[i]);

}
}
}
waltguo 2008-12-17
  • 打赏
  • 举报
回复
不想用foreach,能不能啊。
止戈而立 2008-12-17
  • 打赏
  • 举报
回复
    public static void Foo()
{
int[] a={1,2,3,4,5,6};
int[] b={3,4,5};
ArrayList list=new ArrayList(b);
foreach(int n in a)
{
if(!list.Contains(n))
{
Console.WriteLine(n);

}
}
}

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧