我有以下模型类
public class AssignUserViewModel
{
public IEnumerable<User> Viewrlist { get; set; }
public IEnumerable<User> AssignedViewrlist { get; set; }
}
我将绑定值绑定到它,如下所示。然后比较objassignuser.Viewrlisttry
和objassignuser.AssignedViewrlist
,然后从objassignuser.Viewrlisttry
删除重复内容,如下所示。但这不能正常工作
AssignUserViewModel objassignuser = new AssignUserViewModel();
objassignuser.Viewrlist = ..
objassignuser.AssignedViewrlist = ..
IEnumerable<User> result = (objassignuser.Viewrlist).Except( objassignuser.AssignedViewrlist );
objassignuser.Viewrlist = null;
objassignuser.Viewrlist = result;
答案 0 :(得分:0)
您必须让User
班级实施IEquatable<T>
interface。
一个简单的实现可能如下所示:
class User: IEquatable<User>
{
public int Id{ get; set; }
public string UserName { get; set; }
public bool Equals(User other)
{
return Id == other.Id;
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
}
有关详细信息,请查看here。