Groups | Blog | Home
all groups > c# > april 2007 >

c# : How to use IEquatable?


Patrick H
4/5/2007 4:01:56 PM
Using your info for example it would be IEquatable<List<blah>>


On Apr 5, 5:30 pm, "Paul E Collins" <find_my_real_addr...@CL4.org>
[quoted text, click to view]

Paul E Collins
4/5/2007 11:30:54 PM
I want to implement the equality operation for one of my classes, so
that I can use List<blah>.Contains for a list of those objects instead
of writing a loop to compare with each item in the list.

When I add ": IEquatable" to my class definition, I get a compile
error:
"Using the generic type 'System.IEquatable<T>' requires '1' type
arguments."

What type am I supposed to specify? I just want to write a method that
compares two instances for equality, and the .NET 2.0 docs suggest I
should be using this rather than overriding Equals.

Eq.

Göran_Andersson
4/6/2007 1:00:03 AM
[quoted text, click to view]

The class that you want to compare, i.e. the same class that you are
adding the interface to.

--
Göran Andersson
_____
AddThis Social Bookmark Button