Click here to Skip to main content
11,483,983 members (69,752 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Why we need IComparable interface when we already have Object.Equals method.
As Icomparable gives us CompareTo() method which has same implementation as Object.Equals.

Thanks you very much.
Posted 19-Dec-12 15:29pm
Edited 11-Oct-13 8:08am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Expanding on Christian...

Object.Equals tests if two references are equal (not equality) if the objects are reference types. If the objects are value types, it tests for equality.

The documentation for Object.Equals[^] gives a good example of the difference.

IComparable[^] is used to ensure that an object is comparable to other objects (greater than, less than, or equal to). These can be useful for reference types, for example if you created an Latitude or Longitude type that could compare either a string or decimal number against the object for equality.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 11-Oct-13 23:14pm
   
5ed.
—SA
Ron Beyer at 11-Oct-13 23:53pm
   
Thanks Sergey.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

An interface gives you a common way to work with otherwise different objects. If an object impliments this interface, it can be used by methods that work with this interface.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I think this may help YOU:
An interface gives you a common way to work with otherwise different objects. If an object impliments this interface, it can be used by methods that work with this interface.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 210
1 Frankie-C 155
2 Raje_ 155
3 OriginalGriff 147
4 Maciej Los 110
0 Sergey Alexandrovich Kryukov 8,489
1 OriginalGriff 7,943
2 Sascha Lefèvre 3,114
3 Maciej Los 2,581
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 11 Oct 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100