0
我有两个列表,即列表1和List2如何比较两个列表并查找它们在c#中的不匹配?
想,如果我的列表1具有以下元素,
"first", "second","third"
和我list2中包含以下元素,
"element first is present here"
"elements are present in second"
所以在这种情况下, ,列表2中存在字符串“first”和“second”(但不完全与变量列表中的相同)。
所以在这种情况下,除了“第一个”和“第二个”并显示我的结果,只有“第三个”元素不存在于list2中,我该怎么办?
我使用下面的代码
var inOnlyVariableList = list1.Except(list2).ToList();
由于提前
而关于你的代码是什么故障? – BugFinder
使用版本相等比较器:[Enumerable.Except方法(IEnumerable的,IEnumerable的,的IEqualityComparer )](https://msdn.microsoft.com/en-us/library/bb336390(V = vs.110)。 aspx) –
slawekwin
@BugFinder查询返回列表1中的所有元素。但我只想''第三个''存储在'inOnlyVariableList'变量中。 – Malai