98-372 · Question #14
You are creating a new collection type that must be sorted using Array.Sort by using .NET Framework 4.0. Which of the following interfaces will you use?
The correct answer is D. IComparer. Use the IComparer interface for collections that must be sorted using Array.Sort. The IComparable interface of the System namespace is used to define a generalized comparison method. When a value type or class implements this interface, it creates a type-specific comparison metho
Question
You are creating a new collection type that must be sorted using Array.Sort by using .NET Framework 4.0. Which of the following interfaces will you use?
Options
- AICollection
- BIEqualityComparer
- CIList
- DIComparer
How the community answered
(21 responses)- A5% (1)
- B10% (2)
- D86% (18)
Explanation
Use the IComparer interface for collections that must be sorted using Array.Sort. The IComparable interface of the System namespace is used to define a generalized comparison method. When a value type or class implements this interface, it creates a type-specific comparison method that is the CompareTo method. The CompareTo method compares the current object of a class with another object of the same type. The IComparable interface is also suitable for the sorting mechanism. Answer: B is incorrect. The IEqualityComparer interface is used to support only equality Answer: A is incorrect. The ICollection interface is implemented by all collections to provide the CopyTo() method as well as the Count, IsReadOnly, IsSynchronized, and SyncRoot properties. It is used to define the size, enumerators, and synchronization methods for all non-generic collections. It is the base interface for all classes in the System.Collection namespace. An ICollection interface can be modified. It allows the addition or removal of elements. It does not support sorting. Answer: C is incorrect. The IList interface is used by array-indexable collections. It defines a non- generic collection of objects that can be individually accessed by using the index value. The IList interface is a descendant of the ICollection interface and is the base interface of all non-generic lists. A read-only IList interface cannot be modified. A fixed-size IList interface does not allow the addition or removal of elements.
Topics
Community Discussion
No community discussion yet for this question.