常用算法总结
取两个数组中不相等的部分
int[] a = { 1, 2, 3, 4, 5, 9 };
int[] b = { 1, 4, 5, 7, 8, 9 };
string s_a = "";
string s_b = "";
foreach (int i in a)
{
s_a += i.ToString() + ',';
}
foreach (int i in b)
{
s_b += i.ToString() + ',';
}
string value = "不相同的元素:";
foreach (int i in a)
{
if (!s_b.Contains(i.ToString()))
value += i.ToString() + ",";
}
foreach (int i in b)
{
if (!s_a.Contains(i.ToString()))
value += i.ToString() + ",";
}
Response.Write(value);
如果本文的描述的方法或内容有问题,请给我留言。