What should you do?

You work as an application developer at Domain.com. Domain.com wants you to develop an application that stores and
retrieves client information by means of a unique account number. You create a custom collection class, which implements the IDictionary interface, named ClientDictionary.
The following code have been included into the new application.
//Create Client objects
Client c1 = new Client (“AReid”, “Andy Reid”, Status.Current); Client c2 = new Client (“DAustin”, “Dean Austin”, Status.New); //Create ClientDictionary object
IDictionary cData = new ClientDictionary ();
cData.Add (“10001”, c1);
cData.Add (“10002”, c2);
You use the same method to add other Client objects to the collection. You need to ensure that you are able to retrieve client information associated with the account number 10111.
What should you do?

You work as an application developer at Domain.com. Domain.com wants you to develop an application that stores and
retrieves client information by means of a unique account number. You create a custom collection class, which implements the IDictionary interface, named ClientDictionary.
The following code have been included into the new application.
//Create Client objects
Client c1 = new Client (“AReid”, “Andy Reid”, Status.Current); Client c2 = new Client (“DAustin”, “Dean Austin”, Status.New); //Create ClientDictionary object
IDictionary cData = new ClientDictionary ();
cData.Add (“10001”, c1);
cData.Add (“10002”, c2);
You use the same method to add other Client objects to the collection. You need to ensure that you are able to retrieve client information associated with the account number 10111.
What should you do?

A.
Use the following code:
Client foundClient;
foundClient = (Client) cData.Find (“10111”);

B.
Use the following code:
Client foundClient;
if (cData.Contains (“10111”))
foundClient = cData [“10111”];

C.
Use the following code:
Client foundClient;
if (cData.Contains (“10111”))
foundClient = (Client) cData [“10111”];

D.
Use the following code:
Client foundClient;
foreach (string key in cData.Keys{
if (key == “10111”)
foundClient = (Client) cData.Values [“10111”];
}

Explanation:
This code invokes the Contains method of the IDictionary interface to determine whether a value is associated with the key 10111. If a value exists for that key, then the clientData [“10111”] statement retrieves the client data as a generic object. The code casts the generic object into a Client object, and it is stored in the foundClient variable
Incorrect Answers:
A: You should not use the code that uses the Find method because no such method exists in the IDictionary interface.
B: You should not use the code that assigns the foundClient variable to a generic object because the foundClient variable is declared as a Client type.
D: You should not use the code that iterates through the Keys collection because it is unnecessary and process-intensive.



Leave a Reply 1

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


networkmanagers

networkmanagers

C