【发布时间】:2017-03-03 18:04:16
【问题描述】:
我有两个列表,即 list1 和 list2
假设如果我的 list1 有以下元素,
"first", "second","third"
而我的 list2 有以下元素,
"element first is present here"
"elements are present in second"
所以在这种情况下,字符串“first”和“second”出现在 list2 中。(但与 variablelist 中的不完全相同)。
那么在这种情况下,我怎样才能将“第一”和“第二”除外,并将结果显示为,只有“第三”元素不存在于 list2 中?
我正在使用以下代码
var inOnlyVariableList = list1.Except(list2).ToList();
提前致谢
【问题讨论】:
-
你的代码有什么问题?
-
@BugFinder 查询返回 list1 中的所有元素。但我只想将
"third"存储在inOnlyVariableList变量中。