private void button1_Click(object sender, EventArgs e) { command a = new command(); a.name = textBox1.Text; a.cmd = textBox2.Text; foreach (command c in cmdList) { int i = 0; if (c.name == a.name) { replaceElem(a.cmd, i); return; } } cmdList.Add(a); listBox1.Items.Add(a.name); textBox1.Text = null; textBox2.Text = null; }