3
Reply

Help:how to implement Icomparable uisng generics

Prince

Prince

Mar 17 2010 7:49 AM
2.7k

this is a small portion from my code
public class Rational:IComparable<Rational>
{
// instance variables
private int numerator;
private int denominator;
.
.
.
// interface method with generics

public int CompareTo(Rational otherRational)
{
if (Rational < otherRational)
return -1;
else
if (Rational == otherRational)
return 0;
else
return 1;
}
i have this error message:Rational' is a 'type' but is used like a 'variable' 
i need help!

Answers (3)