Jul 052017
 

I was always getting confused in what to use until i came to know when should we use IEuqatable and IComparable. So lets say you have an object and you want to use it in a dictionary. Sometime we implement the ‘contains’ method from the dictionary on the list. Now this method wont work if the object is not implementing IEquatable. When you implement that method than the purpose of this method is to compare the object with another object. So indirectly we helped our ‘contains’ method which will use this to compare the object.

 

Now lets say there is another requirement in which you want to sort the dictionary then then object used in that dictionary should implement IComparable. By using this interface you will have to implement the compareTo method where you will mention the position of the two objects under observation.

 Posted by at 11:30 am