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
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/suizhikuo/p/11084331.html