1. 取交集

List A :{1,5,9,3,7}

List B:{1,6,8,5,3,2,9,4}

var intersectedList = listA.Intersect(listB, newButtonsListEquality());

结果:{1,3,9}

2.取连集

 List A :{,,,}
List B:{,,,,}
  var bingji = ListA.Union(ListB, new ButtonsListEquality()).ToList();//并(全)集 

结果:{1,2,3,5,6,7,8,9}

3.取差集

List A :{,,,,,}
List B:{,,,,}
var chaji = ListA.Except(ListB, new ButtonsListEquality()).ToList();//差集

结果:{1,2,3,4,7,8,9}

辅助类:

public class ButtonsListEquality : IEqualityComparer<SysButtons>
{
public bool Equals(SysButtons x, SysButtons y)
{
return x.Id == y.Id;
} public int GetHashCode(SysButtons obj)
{
if (obj == null)
{
return ;
}
else
{
return obj.ToString().GetHashCode();
}
}
}
05-11 13:54