Answer the question
In order to leave comments, you need to log in
How to add a word to the dictionary using button1?
Tell me, I am looking for anagrams in the dictionary, there are a certain number of words in this dictionary. When the program does not find this word, the text "The word was not found in the dictionary" is displayed, how to do so, when this word was not found, it could be added by pressing the "Add" button - button1_Click? Below is the anagram code if needed
private void FindWord_Click(object sender, EventArgs e)
{
var dict = new Dictionary<string, string>();
foreach (string line in File.ReadLines(@"1.txt"))
{
dict.Add(line, string.Concat(line.ToLower().OrderBy(c => c))); // Каждое слово из файла приводится к нижнему регистру и сортируется (по буквам) в алфавитном порядке
}
string word = string.Concat(textBox1.Text.ToLower().OrderBy(c => c));
var valStrings = dict.Where(w => w.Value == word).Select(x => x.Key);
richTextBox1.Lines = valStrings.ToArray();
if (valStrings == null || !valStrings.Any()) // проверка слов
{
richTextBox1.Text = richTextBox1.Text + "Слово не было найдено в словаре.";
}
}
private void button1_Click(object sender, EventArgs e)
{
}
Answer the question
In order to leave comments, you need to log in
The dict variable must be made a private member of the class and in button1_Click it will be possible to add it to the dictionary.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question