LINQ获取两个List的交集

1.调用:

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

2.需要重写的方法:

public class MyUserComparer : IEqualityComparer
    {
        public bool Equals(MyUser x, MyUser y)
        {
            //throw new NotImplementedException();
            return x.UserID == y.UserID;
        }
        public int GetHashCode(MyUser obj)
        {
            return obj.ToString().GetHashCode();
        }
    }


你可能感兴趣的:(LINQ)