http://xiangai.taobao.com
http://shop148612228.taobao.com

LINQ获取两个List的交集

1.调用:

UserList = UserList.ToList().Intersect(userIDList, new MyUserComparer()).AsQueryable();

2.需要重写的方法:
public class MyUserComparer : IEqualityComparer<MyUser>
{
public bool Equals(MyUser x, MyUser y)
{
//throw new NotImplementedException();
return x.UserID == y.UserID;
}
public int GetHashCode(MyUser obj)
{
return obj.ToString().GetHashCode();
}
}

---------------------
作者:FreeBeer2015
来源:CSDN
原文:https://blog.csdn.net/anpan1045535101/article/details/40588017
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2019-06-25 18:01  万事俱备就差个程序员  阅读(309)  评论(0编辑  收藏  举报

http://xiangai.taobao.com
http://shop148612228.taobao.com
如果您觉得对您有帮助.领个红包吧.谢谢.
支付宝红包
微信打赏 支付宝打赏