我有一个名为input ...
的对象列表我拿这个列表并过滤它以获得另一个对象列表输出。
我想检查输出列表与输入列表相比是否有任何更改。
列表属于同一类型
答案 0 :(得分:0)
var nonintersect = modifiedList.Except(originalList);
你需要通过isActive字段实现comparer
答案 1 :(得分:0)
您可以将IEquality Comparer
用于此
这是IEquality的通用实现
public class GenericEqualityComparer<T> : IEqualityComparer<T>
{
private Func<T, T, bool> _equalsFunction;
private Func<T, int> _hashCodeFunction;
public GenericEqualityComparer(Func<T, T, bool> equalsFunction, Func<T, int> hashCodeFunction)
{
if (equalsFunction == null) throw new ArgumentException();
if (hashCodeFunction == null) throw new ArgumentException();
_equalsFunction = equalsFunction;
_hashCodeFunction = hashCodeFunction;
}
public bool Equals(T x, T y)
{
return _equalsFunction(x, y);
}
public int GetHashCode(T obj)
{
return _hashCodeFunction(obj);
}
}
样本用法
var difference = List1.Except(list2, new GenericEqualityComparer<Product>((x, y) => x.IsActive== y.IsActive && y.Id== y.Id, x => x.ID.GetHashCode()));
查看msdn