Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dictionary<string, List<double>> studentRecords = new Dictionary<string, List<double>>();
- studentRecords["Angel"] = new List<double>();
- studentRecords["Angel"].Add(5.50);
- studentRecords["Angel"].Add(4.75);
- studentRecords["Angel"].Add(5.25);
- studentRecords["Bogomil"] = new List<double>();
- studentRecords["Bogomil"].Add(5.57);
- Console.WriteLine(studentRecords.Count()); //Displays the number of KeyValuePairs ——> here now 2
- //Down: Way 1 to display only the Keys in a Dict:
- foreach(var keyValuePair in studentRecords)
- {
- Console.WriteLine(keyValuePair.Key);//Displays only the Keys in a Dictionary (Way 1)
- }
- //Down: Way 2 to display only the Keys in a Dict:
- var keys = studentRecords.Keys;//Collection of the existing Keys in a Dictionary (Way 2)
- foreach(var key in keys)
- {
- Console.WriteLine(key); // Displays only the keys
- }
- //Down: Way 3 to Display the Keys in a Dict
- var listOfKeys = new List<string>();
- foreach(var kVP in studentRecords)
- {
- listOfKeys.Add(kVP.Key); //Adds only the Keys to a List
- }
- Console.Write(string.Join(", ", listOfKeys));//Displays the Keys
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement