A little late where I am and probably not the best answer due to my inexperience but how about something like this?
Don't know the efficiency of doing something like that though as it seems like it would get confusing fast.Code:// Class level list containing Text boxes for calculating List<TextBox> txtList = new List<TextBox>(10); public frmMain() { InitializeComponent(); // Add text box to list. Only have to be added in once txtList.Add(txtBox1); txtList.Add(txtBox2); txtList.Add(txtBox3); } private void btnCalculate_Click(object sender, EventArgs e)) { // Run a foreach loop foreach (TextBox t in txtList) { t.Text = Calculate(t.Text, 0.45).ToString(); } } private double Calculate(string firstVal, double secondVal) { // Do some calculation double calcTotal = double.Parse(firstVal) * secondVal; // Return double return calcTotal; }
The only advantage to the code I can see would be the ability to use a foreach loop and change the calculate function to something else without having to write out too much code.




Reply With Quote