Double.TryParse(t1.Text.Trim(), out tr1);
sets tr1 to the numeric value of the text field, or 0.0 if for some reason he was unable to convert it. It will also return true if the conversion was successful or false if it failed, but you do not need to return a value if the default is 0.0.
Added bonus: it will not throw an exception if someone decides to put "This is not a number." in the text box. He will see the value as 0.
To do this in an array ...
TextBox t[] = { t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15 }; double tr[] = new double[t.Length]; for (int i = 0; i < t.Length; ++i) { Double.TryParse(t[i].Text.Trim(), out tr[i]); }
UPDATE:
Note that it is reasonable to expect that you can calculate the average number, which is 0. For this:
TextBox t[] = { t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15 }; double tr[] = new double[t.Length]; int valid_count = 0; for (int i = 0; i < t.Length; ++i) { if (Double.TryParse(t[i].Text.Trim(), out tr[i])) ++valid_count; }
Set the default values ​​for the text fields to "empty" (""), and then you will know how many of them were entered by user 0 and how many were empty. Divide the amount by valid_count to get the exact average. (But make sure valid_count > 0 , or you will most likely get the exception individually.)