Пример #1
0
        // Removes a word and definition
        public void RemoveWordAndDefn(string word)
        {
            int index = DictionaryUtilities.IndexFinder(word, WordListString());

            words       = DictionaryUtilities.ShrinkSizeByOne <TKey>(words, index);
            definitions = DictionaryUtilities.ShrinkSizeByOne <TValue>(definitions, index);
        }
Пример #2
0
        // Returns the definition of the user searched word OR adds definition to the searched word
        public TValue this[TKey searchedWord]
        {
            get
            {
                index = DictionaryUtilities.IndexFinder(Convert.ToString(searchedWord), WordListString());

                if (index >= 0)
                {
                    return(definitions[index]);
                }
                else
                {
                    throw new ArgumentNullException("The searched word is not defined in the dictionary.");
                }
            }

            set
            {
                index = DictionaryUtilities.IndexFinder(Convert.ToString(searchedWord), WordListString());

                if (index >= 0)
                {
                    definitions[index] = value;
                    AlphabetizeDictionary();
                }

                else
                {
                    if (words.Length == definitions.Length)
                    {
                        words       = DictionaryUtilities.GrowSizeByOne(words);
                        definitions = DictionaryUtilities.GrowSizeByOne(definitions);

                        int newLength = words.Length;
                        words[newLength - 1]       = searchedWord;
                        definitions[newLength - 1] = value;
                        AlphabetizeDictionary();
                    }
                    else
                    {
                        Console.WriteLine("There appears to be a mismatch of words to definitions. Program terminating.");
                        Environment.Exit(0);
                    }
                }
            }
        }