On Aug 25, 2:18*pm, Martin Honnen <mahotr...@yahoo.dewrote:
shapper wrote:
I have two lists, A and B. Both are lists of an object named Obj which
has two properties: ID and Name.
I need to check if all items in A exist in B by comparing their names.
If yes, then return true. If not then return false.
Could someone, please, help me creating this?
I tried the following but it is not working:
bool FoundAll = (from b in B
* * * * * * * * * * * * *join a in A on b.Name equals a.Name
* * * * * * * * * * * * *select b).Any();
I think you want
* *bool foundAll = A.All(t =B.Contains(t, new MyComparer()));
where you need to implement
* *class MyComparer : IEqualityComparer<Obj>
* *{
* * * * *public bool Equals(Obj x, Obj y)
* * * * *{
* * * * * * *return x.Name == y.Name;
* * * * *}
* * * * *public int GetHashCode(Obj obj)
* * * * *{
* * * * * * *return obj.Name.GetHashCode();
* * * * *}
* * }
--
* * * * Martin Honnen --- MVP XML
* * * *http://JavaScript.FAQTs.com/
You mean:
using System;
using System.Collections;
class MyComparer : IEqualityComparer<Object{
public bool Equals(Object x, Object y) {
return x.Name == y.Name;
}
public int GetHashCode(Object obj) {
return obj.Name.GetHashCode();
}
}
I get the error:
The non-generic type 'System.Collections.IEqualityComparer' cannot be
used with type arguments
Any idea why?
Thanks,
Miguel