例如,我有两个数组:
var list1 = string[] {"1", "2", "3", "4", "5", "6"};
var list2 = string[] {"2", "3", "4"};
我想做的是——
list1
从and获取常用项目list2
(例如 {"2", "3", "4"})- 获取不同的项目
list1
和list2
(例如。{“1”,“5”,“6”})
所以我尝试过使用 LINQ 并且 -
var listDiff = list1.Except(list2); //This gets the desire result for different items
但,
var listCommon = list1.Intersect(list2); //This doesn't give me desire result. Comes out as {"1", "5", "6", "2", "3", "4"};
有任何想法吗?