C#两个数组消除相同的数据
int[]zong={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,...
int[] zong = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };
int[] zhong={0,0,0,21,4,0,5,0,6,0,2,0,0,0,0,0,0,0,0,0,0,}
zong这个数组去掉 zhong里面有的数据 展开
int[] zhong={0,0,0,21,4,0,5,0,6,0,2,0,0,0,0,0,0,0,0,0,0,}
zong这个数组去掉 zhong里面有的数据 展开
2个回答
展开全部
int[] zong = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int[] zhong= { 0,4,5,6 };
List<int> result= new List<int>();
foreach(int a in zong)
{
if(!zhong.Contains(a))
result.Add(a);
}
zong=new int[result.Count]; //重新设置长度
result.CopyTo(zong); //将List结果复制到数组zong中;
int[] zhong= { 0,4,5,6 };
List<int> result= new List<int>();
foreach(int a in zong)
{
if(!zhong.Contains(a))
result.Add(a);
}
zong=new int[result.Count]; //重新设置长度
result.CopyTo(zong); //将List结果复制到数组zong中;
展开全部
再开一个数组,比如叫int[] result。对于zong中的每一个数,如果在zhong中出现,则不管;如果在zhong中没出现,就加入result。最后result就是你要的结果。伪码:
foreach (int intFromZong in zong)
{
bool hasDuplicate = false;
foreach (int intFromZhong in zhong)
{
if (intFromZong == intFromZhong) { hasDuplicate = true; break;}
}
if (!hasDuplicate) result.Add(intFromZong);
}
foreach (int intFromZong in zong)
{
bool hasDuplicate = false;
foreach (int intFromZhong in zhong)
{
if (intFromZong == intFromZhong) { hasDuplicate = true; break;}
}
if (!hasDuplicate) result.Add(intFromZong);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询