What should you do?

You are currently in the process of reviewing an application that was created by a fellow developer.
The application that you are reviewing includes a declaration for a collection named EmployeeList, which stores Employee objects.
The declaration is shown below:
public class EmployeeList : Enumerator, IEnumerable
{
// Class implementation
}
You require the ability to iterate through the EmployeeList with minimum development effort.
What should you do?

You are currently in the process of reviewing an application that was created by a fellow developer.
The application that you are reviewing includes a declaration for a collection named EmployeeList, which stores Employee objects.
The declaration is shown below:
public class EmployeeList : Enumerator, IEnumerable
{
// Class implementation
}
You require the ability to iterate through the EmployeeList with minimum development effort.
What should you do?

A.
Utilize the switch statement

B.
Utilize the dowhile statement

C.
Utilize the foreach statement

D.
Utilize the if statement

Explanation:
the IEnumerable and IEnumerator interfaces of the System.Collections namespace are used to ensure that your collection class supports foreach iteration. The IEnumerable interface defines only one method named GetEnumerator that returns an object of type IEnumerator of the System.Collections namespace and is used to support iteration over a collection. The IEnumerator interface supports methods, such as Current, MoveNext, and Reset to iterate through a collection. The Current method returns the current element of the collection. The Move method positions the enumerator to the next available element of the collection. The Reset method positions the enumerator before the first element of the collection.
Incorrect Answers:
A D: These statements will not allow you to iterate through the EmployeeList collection.
B: You should not use this statement because it will require manually calling the MoveNext and Current methods. The scenario states that you need to “…iterate through the EmployeeList with minimum development effort.”



Leave a Reply 1

Your email address will not be published. Required fields are marked *