public void TryGet_From_Empty() { HashTable<string, int> table = new HashTable<string, int>(); int value; Assert.IsFalse(table.TryGetValue("missing", out value)); }
public void TryGet_Succeeds() { HashTable<string, int> table = new HashTable<string, int>(); table.Add("100", 100); int value; Assert.IsTrue(table.TryGetValue("100", out value)); Assert.AreEqual(100, value, "The returned value was incorrect"); for (int i = 0; i < 100; i++) { table.Add(i.ToString(), i); Assert.IsTrue(table.TryGetValue("100", out value)); Assert.AreEqual(100, value, "The returned value was incorrect"); } }
public void TryGet_Missing() { HashTable<string, int> table = new HashTable<string, int>(); table.Add("100", 100); int value; Assert.IsFalse(table.TryGetValue("missing", out value)); }
public static void SearchNumbers(HashTable<string, string> phonebook) { string inputName; while (true) { inputName = Console.ReadLine(); if (inputName.Equals("end")) { return; } if (phonebook.ContainsKey(inputName)) { string phonenumber; phonebook.TryGetValue(inputName, out phonenumber); Console.WriteLine("{0} -> {1}", inputName, phonenumber); } else { Console.WriteLine("Contact {0} does not exist.", inputName); } } }