You work as an application developer at Domain.com. You are developing a collection class named ClientCollection,
which is to be used for storing the names of Domain.com’s clients that are situated in various geographical areas.
These client names are represented by the Client class. You are planning to create a method named SortClients in the ClientCollection class to arrange Client objects in ascending order.
You need to ensure that the appropriate interface is implemented by the Client class to allow sorting.
What interface should be used?
A.
IDictionary
B.
IComparable
C.
IComparer
D.
IEqualityComparer
Explanation:
The IComparable interface provides only one method named CompareTo, which takes on generic object, compares it to the current instance, and returns an Integer value representing whether the current instance is equal to, greater than, or less than the object. The IComparable interface is typically used when you want to create a class whose objects can be sorted in either a list or collection.
Incorrect Answers:
A: This interface should not be implemented because it is used to create a collection that is managed by key/value pairs.
C: This interface should not be implemented because it should be implemented by collection or comparer classes, not comparable classes.
D: This interface should not be implemented because it provides methods to compare two objects for equality only.
I have the same idea. B