nerdexam
GIAC

GSSP-NET · Question #326

You work as a Software Developer for ABC Inc. The company uses Visual Studio .NET 2005 as its application development platform. You have created a class named Customer to be used in a billing…

The correct answer is B. foreach (Customer customer in customers) {. See the full explanation below for the reasoning.

Question

You work as a Software Developer for ABC Inc. The company uses Visual Studio .NET 2005 as its application development platform. You have created a class named Customer to be used in a billing application. The Customer class is shown below. class Customer { public string FirstName { get; set; } public string LastName { get; set; } } Each instance of the Customer class contains information about a customer of your company. You have written a segment of code that populates an ArrayList with a collection of Customer objects as shown below. ArrayList customers = new ArrayList(); Customer myCustomer = new Customer(); myCustomer.FirstName = "Helen"; GIAC GSSP-.NET Exam myCustomer.LastName = "of Troy"; customers.Add(myCustomer); myCustomer = new Customer(); myCustomer.FirstName = "Elvis"; myCustomer.LastName = "Presley"; customers.Add(myCustomer); You need to write code that iterates through the customers ArrayList and displays the name of each customer at the command prompt. Which code segment should you choose?

Options

  • Aforeach (Customer customer in customers) {
  • Bforeach (Customer customer in customers) {
  • Cfor (int counter = 0; counter <= customers.Count; counter++)
  • Dfor (int counter = 0; counter <= customers.Count; counter++)

How the community answered

(35 responses)
  • A
    14% (5)
  • B
    77% (27)
  • C
    6% (2)
  • D
    3% (1)

Community Discussion

No community discussion yet for this question.

Full GSSP-NET Practice