How do I see common Items between 2 array of Objects. My intersect is not returning anything. The object is created from a Linq to SQL class.
+1
A:
In Java atleat, unless you override the .equals() operator, it will test for object equality (essentially using ==). That might be why the intersection is emtpy.
Mike Pone
2009-05-14 15:33:16
A:
You will need to override the object's Equals method. You can find some guidelines at Microsoft's web site.
I've provided a sample below:
public override bool Equals(System.Object obj)
{
if (obj != null && obj is MyClass)
{
MyClass obj2 = (MyClass)obj;
return (obj2.ID == this.ID);
}
}
If you do not override this method, any kind of sort/intersect/comparison will compare the objects based on their reference; so, if two objects refer to the same spot in memory, they are considered "equal."
Ed Altorfer
2009-05-14 17:18:03
Thanks you very much.
Greens
2009-05-14 17:28:23
My class definition is in the web service and I am trying to do the intersect in the client side. I overrided the Equals method still didnt work.
Greens
2009-05-14 18:38:07
Also my intersect doesnt work.
Greens
2009-05-14 18:51:33
Your comments don't really give me enough detail to provide you with a better solution. If you could provide an example of what you're doing, it would make for a more succinct question.
Ed Altorfer
2009-05-14 20:25:16