public void Add(TKey key, TValue value) { int idx = GetIdx(key); if (_subDict[idx] != null) { _subDict[idx].Add(key, value); } else { _subDict[idx] = new DictionaryMd <TKey, TValue>(_size, _sizeOrigin, key, value); } _count++; }
private void SetValueByKey(TKey key, TValue value) { if (_subDict == null) { _singleValue = value; return; } int idx = GetIdx(key); if (_subDict[idx] == null) { _subDict[idx] = new DictionaryMd <TKey, TValue>(_size, _sizeOrigin, key, value); } else { _subDict[idx].SetValueByKey(key, value); } }
static void Main(string[] args) { Console.WriteLine("Hello World! Let's count."); IDictionary <int, string> dict = new DictionaryMd <int, string>(100); dict[9] = "nine"; dict.Add(8, "eight"); Console.WriteLine($"{dict[9]}"); Console.WriteLine($"{dict[8]}"); dict[9] = "NINE"; Console.WriteLine($"{dict[9]}"); Console.WriteLine($"{dict[8]}"); try{ dict.Add(9, "akward"); } catch (Exception e) { Console.WriteLine($"Exception: \n '{e.GetType()}'\n '{e.Message}'"); } Console.WriteLine("Goodbye..."); }