Complete the code to add a key-value pair to the dictionary.
var map = new Dictionary<string, int>(); map.[1]("apple", 5);
The Add method inserts a new key-value pair into the dictionary.
Complete the code to check if a key exists in the dictionary.
if (map.[1]("apple")) { Console.WriteLine("Found apple!"); }
ContainsKey checks if the dictionary has the given key.
Fix the error in accessing a value by key.
int value = map[[1]];Keys in the dictionary are strings, so use the string "apple" to access the value.
Fill both blanks to create a dictionary with initial values and check a key.
var map[1] new Dictionary<string, int> { {"apple", 5}, {"banana", 3} }; bool hasBanana = map.[2]("banana");
Use = to assign the dictionary with initial values, and ContainsKey to check if "banana" exists.
Fill all three blanks to create a dictionary, add a new item, and retrieve a value.
var map = new Dictionary<string, int>(); map.[1]("orange", 7); int orangeCount = map[[2]]; Console.WriteLine(orangeCount [3] 0);
Use Add to insert "orange" with value 7, access it by key "orange", and check if the count is greater than 0.
