public class EmployeeCollection :

Domain.com wants you to develop an application that stores and retrieves employee information
by means of a unique staff number.
You create a custom collection class, which implements the type-safe IDictionary interface.
This collection class is named EmployeeCollection, and is defined using the following code.
public class EmployeeCollection : IDictionary {
// Implementation code
}

Domain.com wants you to develop an application that stores and retrieves employee information
by means of a unique staff number.
You create a custom collection class, which implements the type-safe IDictionary interface.
This collection class is named EmployeeCollection, and is defined using the following code.
public class EmployeeCollection : IDictionary {
// Implementation code
}

A.
Use the following code:
Employee e1, e2;
e1 = new Employee (1001, “Andy Reid”, “Manager”);
e2 = new Employee (1002, “Kara Lang”, “Sales Engineer”);
EmployeeCollection eData = new EmployeeCollection();
eData.Add (new KeyValuePair (e1.ID, e1));
eData.Add (new KeyValuePair (e2.ID, e2));

B.
Use the following code:
Employee e1, e2;
e1 = new Employee (1001, “Andy Reid”, “Manager”);
e2 = new Employee (1002, “Kara Lang”, “Sales Engineer”);
EmployeeCollection eData = new EmployeeCollection();
eData.Add ((string) e1.ID, e1);
eData.Add ((string) e2.ID, e2);

C.
Use the following code:
Employee e1, e2;
e1 = new Employee (1001, “Andy Reid”, “Manager”);
e2 = new Employee (1002, “Kara Lang”, “Sales Engineer”);
EmployeeCollection eData = new EmployeeCollection();
eData.Add (e1.ID, e1);
eData.Add (e2.ID, e2);

D.
Use the following code:
Employee e1, e2;
e1 = new Employee (1001, “Andy Reid”, “Manager”);
e2 = new Employee (1002, “Kara Lang”, “Sales Engineer”);
EmployeeCollection eData = new EmployeeCollection();
eData.Add (new KeyValuePair (e1.ID, e1));
eData.Add (new KeyValuePair (e2.ID, e2));

Explanation:
This code instantiates two Employee objects and an EmployeeCollectionobject, and it adds those two Employee objects to the EmployeeCollection object. The EmployeeCollection class implements the generic IDictionary interface specifying the ckey and TValue placeholders as Integer and Employee data types, respectively. Like the non-generic IDictionary interface, the key is used to retrieve the value. Unlike the non-generic IDictionary interface, the key does not have to be a string and the value does not have to be a generic object. Unlike the non-generic IDictionary interface, the Add method of the generic IDictionary interface can accept either a KeyValuePair structure with the appropriate data types specified or in this case two arguments, an integer and Employee object.
Incorrect Answers:
A: If you use this code fragment, the EmployeeCollection class accepts an integer foe the CKey placeholder and an Employee object for the TValue placeholder.
B: You should not use the code that casts the ID property from an integer into a string, because the key value should match the integer data type defined by CKey placeholder of the generic IDictionary interface.
D: You should not use the code that does not specify the CKey and TValue placeholders when using the KeyValuePair structure because the data types must be declared explicitly.



Leave a Reply 1

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


networkmanagers

networkmanagers

I have the same idea. C