How to use IEquatable?

  • Thread starter Thread starter Paul E Collins
  • Start date Start date
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.
 
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.
 
Back
Top