循環遍歷不相同的元素
發布時間:2016-12-28 21:16
作者:獨孤劍
閱讀:984
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() + ",";
}
Console.WriteLine(value);
/*
------輸出結果------------
不相同的元素:2,3,7,8,
*/
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞