On Jul 10, 3:08*pm, Jon Skeet [C# MVP] <sk...@pobox.com> wrote:
> Author <gnewsgr...@gmail.com> wrote:
> > I understand that if we wanna compare two objects of the same class,
> > we need to implement the IComparable interface, as shown here:
>
> >http://msdn.microsoft.com/en-us/library/system.icomparable.compareto(...
>
> > I am confused by the implementation of the CompareTo method in the C#
> > example on the above page. *Look:
>
> > public int CompareTo(object obj)
> > {
> > * * * * if(obj is Temperature)
> > * * * * {
> > * * * * * * Temperature otherTemperature = (Temperature) obj;
> > * * * * * * return
> > this.temperatureF.CompareTo(otherTemperature.temperatureF);
> > * * * * }
> > * * * * else
> > * * * * {
> > * * * * * *throw new ArgumentException("object is not a Temperature");
> > * * * * }
> > }
>
> > The thing that baffles me is that the implementation of CompareTo
> > makes a call to this method itself.
>
> Where? It looks to me like it's calling double's implementation of
> CompareTo.
>
> --
> Jon Skeet - <sk...@pobox.com>
> Web site:http://www.pobox.com/~skeet*
> Blog:http://www.msmvps.com/jon_skeet
> C# in Depth:http://csharpindepth.com
That's right. So, double actually implements CompareTo like what I
did. That must be it. Thank you.