//am having errors on this portion of my code
// am require to implement Icomparable interface with my rational class

// 
   
  public int CompareTo(Rational opnd1,Rational opnd2 )
         {
             if (Rational opnd1 < Rational opnd2)
             return -1;
             else (Rational opnd1 == Rational opnd2)
             return 0;
             else 
             return 1;
using System;

class Program
{
    static void Main(string[] args)
    {
        Foo foo = new Foo();
        foo.Blah = 17;

        Foo foo2 = new Foo();
        foo2.Blah = 36;

        foo.CompareTo(foo2); // uses IComparable<Foo> implementation

        ((IComparable)foo).CompareTo(foo2); // uses IComparable implementation
    }
}

public class Foo : IComparable<Foo>, IComparable
{
    public int Blah { get; set; }

    #region IComparable<Foo> Members

    public int CompareTo(Foo other)
    {
        return this.Blah.CompareTo(other.Blah);
    }

    #endregion

    #region IComparable Members

    int IComparable.CompareTo(object obj)
    {
        return this.CompareTo((Foo)obj);
    }

    #endregion
}

Here's for another round of "getting to know your IDE." When you inherit from an interface, after you type in the name of the interface a blue bar will appear under the first character of the interface name. Hover over it and you'll get a drop down that allows you to create the implementation shell of the interface's members. You'll get the right signatures, all you need to do at that point is put in the proper implementation. (Your signature above was incorrect from the start, it looks like you are going for the similarly named IComparer interface instead.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.