473,473 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

IComparable Question

In the first class below, I get an error that
AnotherClientBaseDataRecord does not implement
IComparable.CompareTo(object)...yet the second class below is
implemented identicially and it does get the compile error. I'd love
help understanding this :=) ....

Why does this not compile
public class AnotherClientBaseDataRecord : IComparable
{
public AnotherClientBaseDataRecord() {}
public int CompareTo(AnotherClientBaseDataRecord otherRecord) {
return 0;}
}

public class BuildFileRecord : IComparable
{
public BuildFileRecord () {}
public int CompareTo(BuildFileRecord otherRecord) { return 0;}
}
Nov 15 '05 #1
1 1431
"raffelm" <ma*********@mindspring.com> wrote in message
news:ba**************************@posting.google.c om...
In the first class below, I get an error that
AnotherClientBaseDataRecord does not implement
IComparable.CompareTo(object)...yet the second class below is
implemented identicially and it does get the compile error. I'd love
help understanding this :=) ....

Why does this not compile
public class AnotherClientBaseDataRecord : IComparable
{
public AnotherClientBaseDataRecord() {}
public int CompareTo(AnotherClientBaseDataRecord otherRecord) {
return 0;}
}

public class BuildFileRecord : IComparable
{
public BuildFileRecord () {}
public int CompareTo(BuildFileRecord otherRecord) { return 0;}
}


Hi raffelm,

You need to make the signature of the CompareTo method match what is defined
in IComparable:

public class AnotherClientBaseDataRecord : IComparable
{
public AnotherClientBaseDataRecord() {}
public int CompareTo(object otherRecord)
{
return 0;}
}

public class BuildFileRecord : IComparable
{
public BuildFileRecord () {}
public int CompareTo(object otherRecord) { return 0;}
}

BTW, you should have received compile errors for both classes. To prove
that you will receive an error for BuildFileRecord, fix
AnotherClientBaseRecord first and recompile.

Joe
--
http://www.csharp-station.com
Nov 15 '05 #2

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

Similar topics

2
by: Simon | last post by:
Hi all I have a class implements IComparable interface, however, I got a error on the following method protected override int IComparable.CompareTo(object value .. Does anyone know the...
3
by: Cybertof | last post by:
Hello, Could someone please explain me the difference between the 2 interfaces IComparable and IComparer ? In which cases use one or the other ? Are they dedicated to own classes or built-in...
2
by: ESPNSTI | last post by:
Hi, I'm trying to use a generics dictionary with a key class that implements and needs IComparable<>. However when I attempt to use the dictionary, it doesn't appear to use the IComparable<> to...
2
by: Stefan L | last post by:
Hi everybody, when migrating to the .NET 2.0 framework we decided to encourage the use of generic functions because they ought to run faster than their equivalent object-implemantations. Now...
4
by: Michel Walsh | last post by:
Question: public static Boolean In<T>(T x, param T y) where T : struct, IComparable<T> { for(int i=0; i<y.Length; i++) { if(x==y) return true; } return false;
1
by: Brett Romero | last post by:
What are the reasons to use one over the other? SortedList implements IComparer.Compare(). Why would you also want to create a SortedList class that implements IComparable.CompareTo()? I know...
8
by: SimeonArgus | last post by:
I need to sort a list of points, so I've considered using an IComparable implementation. Should be easy, right? But I need to know two things in the CompareTo function, not one. Test1: I need to...
3
by: Samuel R. Neff | last post by:
You can you program against generic interfaces generically? For example, how can I make the following code which works for the non-generic interface also work for the generic counterparts? ...
5
by: John Devlon | last post by:
Hi everyone, With this post I would like to ask you all a small question. I'm trying to sort an array of objects using IComparable. Adding below displayed code to a class and triggering the...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.