Using LINQ's Except method with an object from an external API?

If you want to compare anchors using the default Equals method, which in this case will probably give you reference equality, you don't need to do anything: just pass the set of anchors to exclude: anchors. Except(anchorsToExclude) If the members of the sequence to exclude will not be reference-equal (or whatever HtmlAnchor. Equals deems equal), the interface you want to implement is IEqualityComparerHtmlAnchorEqualityComparer which implements IEqualityComparer.

If you want to compare anchors using the default Equals method, which in this case will probably give you reference equality, you don't need to do anything: just pass the set of anchors to exclude: anchors. Except(anchorsToExclude); If the members of the sequence to exclude will not be reference-equal (or whatever HtmlAnchor. Equals deems equal), the interface you want to implement is IEqualityComparer.

This exists precisely to allow you to provide a custom equality comparison for a type that you don't define, so the rules don't change -- you just have to use the appropriate overload of Except. So you would create a class called e.g. HtmlAnchorEqualityComparer which implements IEqualityComparer, and pass an instance of that to Except: anchors. Except(anchorsToExclude, new HtmlAnchorEqualityComparer()).

When you don't have control over the type, and the default equality operations do not suffice (ie. Equals is not properly implemented), you should use the overload which takes an IEqualityComparer parameter. This is a class that you can implement yourself to provide the definition of equality, that you need.

I have a List of HTMLAnchor objects (HTMLAnchor is an object from an external API). Using LINQ, I can use the Except operator. However, on here (http://msdn.microsoft.com/en-us/vcsharp/aa336761.aspx#except1), the example using the custom type (Product if I remember correctly) does not use the overloaded version of Except.

Furthermore, if I am using a type not defined by me, do the rules change? And should the class I write to implement IEquality have the same name I am trying to exclude in my generic collection (HtmlAnchor)?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions