在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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.取连集 1 List A :{1,5,9,6} 2 List B:{6,8,7,2,3} var bingji = ListA.Union(ListB, new ButtonsListEquality()).ToList();//并(全)集 结果:{1,2,3,5,6,7,8,9}
3.取差集 List A :{1,2,3,4,5,6} List B:{5,6,7,8,9} 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 0; } else { return obj.ToString().GetHashCode(); } } }
|
请发表评论