473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to use IEquatable?

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.
Apr 5 '07 #1
2 5530
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>
wrote:
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.

Apr 5 '07 #2
Paul E Collins wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Apr 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: JohnR | last post by:
I'm trying to find a way to create a variable of a given type at runtime where I won't know the type until it actually executes. For example, dim x as object = "hi" x is declared as an object...
9
by: Michael D. Ober | last post by:
In the code below, the IComparator function is never called. What am I missing? Public Class ArchiveInfo Implements System.IComparable(Of ArchiveInfo) Public FullName As String = "" Public...
11
by: herpers | last post by:
Hello, I probably don't see the obvious, but maybe you can help me out of this mess. The following is my problem: I created two classes NormDistribution and DiscDistribution. Both classes...
11
by: Marc Gravell | last post by:
This one stumped me while refactoring some code to use generics... Suppose I declare an enum MyEnum {...} Is there a good reason why MyEnum doesn't implement IEquatable<MyEnum> ? Of course,...
9
by: thomson | last post by:
Hi All, i do have a customer table in the Customer class i do have a function which fetches data from the table and assign to the customer properties, Ok, In the Front end , i get all these...
8
by: semedao | last post by:
Hi I have some Queue object that I enqueue other objects into it. I want to check if someobject already exists before enqueue , using the Contains method but italways return false. in the object...
3
by: kim.nolsoee | last post by:
Hi I want to use the Dictionary Classs that will load my own class called KeyClass used as TKey. Here is the code: public class Dictionary { public static void Main()
5
by: taumuon | last post by:
I've got an object, Person, that supports IEquatable<Person>. It implements bool Equals(Person obj) as well as overriding bool Equals(object obj) I've got a container type that holds a member...
5
by: Anders Borum | last post by:
Hi! While implementing a property manager (that supports key / value pairs), I was wondering how to constrain T to a struct or string type. Basically, I guess what I'm looking for is the common...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.