Ok, So first I must say that everything I know about coding I have learned on my own in my spare time so bear with me if my code is primitive, but please, I am open to any comments to make me better...
Anyway, as for my question. I have an application I am building in C# for .NET Compact Framework (for an HP iPaq) the program's purpose is to act similarly to a Restaurant POS terminal to "ring up" food orders. it has gotten to the point where some of my code is the same line copied god even knows how many times with only a numerical difference between them. here is an example:
private void button9_Click(object sender, EventArgs e)
{
AddItem(buttonNames[0], prices[0]);
}
private void button14_Click(object sender, EventArgs e)
{
AddItem(buttonNames[1], prices[1]);
}
private void button5_Click(object sender, EventArgs e)
{
AddItem(buttonNames[2], prices[2]);
}
private void button10_Click(object sender, EventArgs e)
{
AddItem(buttonNames[3], prices[3]);
}
private void button13_Click(object sender, EventArgs e)
{
AddItem(buttonNames[4], prices[4]);
}
private void button4_Click(object sender, EventArgs e)
{
AddItem(buttonNames[5], prices[5]);
}
or
button9.Text = buttonNames[0];
button14.Text = buttonNames[1];
button5.Text = buttonNames[2];
button10.Text = buttonNames[3];
button13.Text = buttonNames[4];
button4.Text = buttonNames[5];
button11.Text = buttonNames[6];
button15.Text = buttonNames[7];
button7.Text = buttonNames[8];
button12.Text = buttonNames[9];
button16.Text = buttonNames[10];
button8.Text = buttonNames[11];
I KNOW there are easier ways to do a lot of the code I have written, I just don't know how to do it.
Buttons[0].name
,Buttons[0].price
,Buttons[0].buttonControl
, etc. \$\endgroup\$