常用算法总结

取两个数组中不相等的部分
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);

 

posted on 2010-03-11 11:32  几度夕阳红了  阅读(242)  评论(0编辑  收藏  举报