static void Main(string[] args) { HashTable <String, String> table = new HashTable <string, string>(2); table.Add("Name", "Ivan"); table.Add("Surname", "Petrov"); try { table.Add("Surname", "Petrov"); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } table.Add("Phone Number", "1234567890"); var val = table.GetValue("Surname"); Console.WriteLine(val); try { val = table.GetValue("Bad"); }catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } table.Clear(); table.Add("Name", "Ivan"); table.Add("Surname", "Petrov"); table.Add("Phone Number", "1234567890"); Console.ReadKey(); }
public static void Main() { HashTable <int, string> testTable = new HashTable <int, string>(); testTable.Add(1, "test"); string test = testTable.GetValue(1); Console.WriteLine(test); testTable.Delete(1); Console.WriteLine(testTable.GetValue(1)); }
public void TestGetValueMethod() { var hashTable = new HashTable<int, int>(); hashTable.Add(1, 2); hashTable[2] = 3; Assert.AreEqual(2, hashTable.Count); Assert.AreEqual(2, hashTable[1]); Assert.AreEqual(2, hashTable.GetValue(1)); Assert.AreEqual(3, hashTable[2]); Assert.AreEqual(3, hashTable.GetValue(2)); }
public void TestGetValueMethodShouldThrowException() { var hashTable = new HashTable<int, int>(); hashTable.Add(1, 2); hashTable[2] = 3; hashTable.GetValue(3); }
static void Main(string[] args) { int size = 252; HashTable <int, int> hashTable = new HashTable <int, int>(size); hashTable.Add(1, 1); hashTable.Add(1, 2); hashTable.Add(3, 5); hashTable.Add(4, 3); hashTable.Add(5, 4); hashTable.Add(8, 6); hashTable.Add(13, 7); hashTable.Show(); Console.WriteLine(hashTable.Delete(13)); hashTable.Show(); Console.WriteLine(hashTable.GetValue(8)); Console.ReadKey(); }