How to use IEquatable?

P

Paul E Collins

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.
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Paul said:
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.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top