I have two List, this complex object has 4 public properties of reference type.
How can i compare one list to another to find if those lists are equal in size and by values.
I have implemented Equals in ComplexObject in order to help with equality checks
public Type1 Type1 { get; set; }
public IEnumerable<Type2> Type2s{ get; set; }
public Type3 Type3{ get; set; }
public Type4 Type4 { get; set; }
public bool Equals(ComplexObject complexObject)
{
int type2sCount = Type2s.Count();
return Type1 .Equals(complexObject.Type1) &&
Type3.Equals(complexObject.Type3) &&
Type4.Equals(complexObject.Type4) &&
Type2s.Intersect(complexObject.Type2s).Count() == type2sCount;
}
I need also to print out items that do no fit or have no pair in second list
Thanks
The simplest approach for the lists would be
SequenceEqual, but you need to be careful aboutnulls: