2011-07-17 36 views

回答

2

可以使用SequenceEqual - 方法:

bool equal = obj1.ClassChildren.SequenceEqual(obj2.ClassChildren) 

使用默認的相等比較器使用自定義一見HERE或這個例子:

class ClassChildComparer : IEqualityComparer<ClassChild> 
{ 
    public bool Equals(ClassChild x, ClassChild y) 
    { 
     return x.Property == y.Property; 
    } 

    // If Equals() returns true for a pair of objects then GetHashCode() must return the same value for these objects. 
    public int GetHashCode(ClassChild c) 
    { 
     return c.Property.GetHashCode(); 
    } 

} 

//and then: 

bool equal = obj1.ClassChildren.SequenceEqual(obj2.ClassChildren, new ClassChildComparer()) 
相關問題