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!
Loading
PriyankaPosted Mar 17, 2010, 9:12 AM
Hi Prince,
You have this setting because of the statement:
if (Rational < otherRational)
There are two reasons why this statemet is wrong:
For "==" operator also you need to provide this in place of Rational, so as to check for reference equals with otherRational.
Hope this clears you doubt.!!!!!
Let know if you have any other query.
PrincePosted Mar 17, 2010, 8:53 AM
Amit ChoudharyPosted Mar 17, 2010, 8:40 AM
What are you really doing in this code:
if (Rational < otherRational)
Rational is a Type {class name} and you comaparing it with its object .....
To have some good example for IComparable interface implemetation download the attach file and see how it works.
Please mark as answer if it helps.