日期:2014-05-20 浏览次数:20543 次
public static void GetA1() { string[] a = { "不错", "好的", "good", "ok", "9", "15", "od" }; string[] b = { "真不错", "好的", "good", "ok", "15", "odd", "look", "dddd" }; string result1=string.Empty; string result2=string.Empty; foreach (string str1 in b) { if (!a.Contains(str1)) result1 += str1 + "|"; } foreach (string str1 in a) { if (!b.Contains(str1)) result2 += str1+"|"; } Console.WriteLine(result1); Console.WriteLine(result2); }
------解决方案--------------------
public static void GetA1() { string[] a = { "不错", "好的", "good", "ok", "9", "15", "od" }; string[] b = { "真不错", "好的", "good", "ok", "15", "odd", "look", "dddd" }; var list1 = b.Where(item => !a.Contains(item)).ToList(); var list2 = a.Where(item => !b.Contains(item)).ToList(); foreach (string result1 in list1) Console.WriteLine(result1); foreach (string result2 in list2) Console.WriteLine(result2); }