LINQ如何获得差异

时间:2013-06-15 06:16:09

标签: asp.net linq

我有两个列表

var items = new[] { "one", "two", "three" };
var items2 = new[] { "one" };

我想比较两个列表并获取items2中不可用的项目。基本上需要以下输出

two three

2 个答案:

答案 0 :(得分:2)

试试这个

items.Except(items2).ToList().ForEach(x=>Console.Write(x));

答案 1 :(得分:2)

items.Except(items2);

会给你预期的结果。