You need to add the numbers to the array of numbers you declared
double[] numbers = new double[5];
Right now you are just declaring a new variable in addButton_Click called number and not doing anything with it.
It might be easier to use a list of numbers. I.E
List<double> numbers = new List<double>();
Then in addButton_Click just add the number
numbers.Add(mynumber);
You have declared an array of length 5 in the class this means you will need to declare an index variable and do bounds checking to make sure after the addButton is click that the array isnt full. I.E once the user clicks the button more than 5 times. Using the list avoids that effort.
Also you will have an exception in the addButton_Click handler if the user types in a non number value into the text box. You should also look to change that to something like double.TryParse.
public partial class Default : System.Web.UI.Page
{
public List<double> numbers
{
get
{
var list = ViewState["mylist"];
if (list == null) ViewState["mylist"] = new List<double>();
return ViewState["mylist"] as List<double>;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void addButton_Click(object sender, EventArgs e)
{
string value;
double number;
value = numberTB.Text;
if (Double.TryParse(value, out number)) numbers.Add(number);
// you should display some sort of message if the value isnt a number...
}
}
Since this is asp.net web forms you also need to stick the member variable in ViewState or Session otherwise the list or array / whatever will always be empty as web forms doesn't automatically persist member variable values for you.
int index = 0, and donumers[index] = number. Then increment the indexindex++.List<double>. You can't modify an array's size.