我们知道取出两个数组中相等的部分,很容易,只要判断相等就行了。那么怎样去除两个数组中不相等的部分呢?
看代码:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
using System;
using System.Collections;
using System.Text;
namespace CharOperate
{
class Program
{
static void Main()
{
string[] strraw ={ "29", "34", "89" };
string[] strnow ={ "29", "20", "23" };
ArrayList rest = new ArrayList();
for (int i = 0; i < strraw.Length; i++)
{
for (int j = 0; j < strnow.Length; j++)
{
if (strraw[i] == strnow[j])
{
goto lhking;
}
else
{
if (j == strnow.Length - 1)
{
rest.Add(strraw[i]);
}
}
}
lhking: ;
}
for (int i = 0; i < strnow.Length; i++)
{
for (int j = 0; j < strraw.Length; j++)
{
if (strnow[i] ==strraw [j])
{
goto lhking;
}
else
{
if (j == strraw.Length - 1)
{
rest.Add(strnow[i]);
}
}
}
lhking: ;
}
foreach (string str in rest)
{
Console.Write(str + " ");
}
Console.Read();
}
}
}
以上的goto可以语句,可以换成break