PART II
C h a p t e r 2 4 :
C o l l e c t i o n s , E n u m e r a t o r s , a n d I t e r a t o r s
789
static void Main() {
// Create a Dictionary that holds employee
// names and their corresponding salary.
Dictionary dict =
new Dictionary();
// Add elements to the collection.
dict.Add("Butler, John", 73000);
dict.Add("Swartz, Sarah", 59000);
dict.Add("Pyke, Thomas", 45000);
dict.Add("Frank, Ed", 99000);
// Get a collection of the keys (names).
ICollection c = dict.Keys;
// Use the keys to obtain the values (salaries).
foreach(string str in c)
Console.WriteLine("{0}, Salary: {1:C}", str, dict[str]);
}
}
Here is the output:
Butler, John, Salary: $73,000.00
Swartz, Sarah, Salary: $59,000.00
Pyke, Thomas, Salary: $45,000.00
Frank, Ed, Salary: $99,000.00
Do'stlaringiz bilan baham: |