nerdexam
Microsoft

98-372 · Question #38

98-372 Question #38: Real Exam Question with Answer & Explanation

The correct answer is B. IEnumerable. You will implement the IEnumerable interface. The IEnumerable interface is used to represent the enumerator that supports a simple iteration over a non-generic collection. It supports the for-each loop. Therefore, IEnumerable interface must be implemented to support the for-each

Question

You create an application using .NET Framework 4.0. You are creating a new collection type that must be iterated using a for-each loop in the application. Which of the following interfaces will you implement?

Options

  • AIOrderedDictionary
  • BIEnumerable
  • CIDictionary
  • DIEqualityComparer

Explanation

You will implement the IEnumerable interface. The IEnumerable interface is used to represent the enumerator that supports a simple iteration over a non-generic collection. It supports the for-each loop. Therefore, IEnumerable interface must be implemented to support the for-each loop. All types of COM classes that use enumerators can also implement the IEnumerable interface. It contains only one method named as GetEnumerator(). Answer: C is incorrect. The IDictionary interface represents a non-generic collection of key/value pairs. It is the base interface for all the non-generic collections of key/value pairs. The IDictionary implementations fall into three categories, which are as follows: 1.Read-only: An IDictionary object cannot be modified. 2.Fixed size: An IDictionary object cannot be allowed to add or remove elements. 3.Variable size: An IDictionary object can add, remove, or modify elements. The IDictionary interface does not allow any sorting. Answer: A is incorrect. The IOrderedDictionary interface represents an indexed collection of key and value pairs. It is a new interface introduced by .NET Framework 2.0. The contents of the IOrderedDictionary interface can be accessed either with the key or with the index. Each element (key and value pair) is stored in a DictionaryEntry structure. It is similar to the IList and IDictionary interfaces. Each pair should have a unique key that is not null, but the value can be null and does not have to be unique. It ensures that items can be accessed, inserted, and removed by index or Answer: D is incorrect. The IEqualityComparer interface provides a method to support the comparison of objects for equality. It provides two methods, namely Equal() and GetHashCode(). Equal() checks two objects for equality, whereas GetHashCode() returns a hash code for the specified object. It supports only equality comparisons.

Community Discussion

No community discussion yet for this question.

Full 98-372 Practice