I have 3 textboxes named from a_box
to c_box
.
I am trying to write one method that will allow me to check each textbox for a double. At the moment I have to use 3 seperate methods, each one tailored to their respective textbox (see below).
public void CheckA() {
if(Double.TryParse(a_box.Text, out a)) {
return a;
} else {
logbox.AppendText ("Box A does not contain a double\r\n");
a_box.Text = ("NO DOUBLE FOUND")
a = double.NaN;
return a;
}
}
In an ideal world I would be able to substitute in the name of the textbox and just have one copy of the method that is able to process all the textboxes. To give you some context, I imagine it would look like so..
String aa = ("a");
String bb = ("b");
String cc = ("c");
Double a = CheckAll(aa);
Double b = CheckAll(bb);
Double c = CheckAll(cc);
public double CheckAll(string name) {
Double value;
String textbox = name + "_box";
if (Double.TryParse(textbox, out value) {
return value;
} else {
logbox.AppendText ("Box " + name + " does not contain a double");
textbox.Text = ("NO DOUBLE FOUND");
value = double.NaN
return value;
}
}
If anyone is able to tell me what the code should actually look like I would really love to know as it would help me a lot if I come to modify the process if the future or if I need to add another layer of complexity later on.