Избавление от повторений - C#
Формулировка задачи:
В общем есть следующий код. Как его почистить от повторений?
private void btnEncrypt_text_Click(object sender, EventArgs e) { if (textBox_key.Text != String.Empty) { cryptText = true; myCrypt = new MyCrypter(textBox_key.Text, "Veni, Vedi, Vici"); richTextBox_output.Text = myCrypt.Encrypt(richTextBox_input.Text); } else { MessageBox.Show("Need to set Key"); } } private void btnDecrypt_text_Click(object sender, EventArgs e) { if (textBox_key.Text != String.Empty) { cryptText = true; myCrypt = new MyCrypter(textBox_key.Text, "Veni, Vedi, Vici"); richTextBox_output.Text = myCrypt.Decrypt(richTextBox_input.Text); } else { MessageBox.Show("Need to set Key"); } }
Решение задачи: «Избавление от повторений»
textual
Листинг программы
private void btnEncrypt_text_Click(object sender, EventArgs e) { Foo(false); } private void btnDecrypt_text_Click(object sender, EventArgs e) { Foo(true); } void Foo(bool decrypt) { if (textBox_key.Text != String.Empty) { cryptText = true; myCrypt = new MyCrypter(textBox_key.Text, "Veni, Vedi, Vici"); if(decrypt) richTextBox_output.Text = myCrypt.Decrypt(richTextBox_input.Text); else richTextBox_output.Text = myCrypt.Encrypt(richTextBox_input.Text); } else { MessageBox.Show("Need to set Key"); } }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д