This is "homework" (in my c# book)
What should happen is on a textbox a user inputs 10 numbers (one at a time I would do it) and each time he clicks the button "addValBtn" it should add that number to the array until it fills up 10 spots with 10 user inputted numbers. Then I'm trying to display that array via the displayValBtn (which I can figure out myself) but I just cant get this damn array to work correctly.
My book explained how to set up an array fine, and from what I read on Stackoverflow and off Google people had similar questions. But none of them seemed to take input each time you click the button. So I'm at a loss of what to do exactly.
I created and defined my array as numArray (using double) - set my array index to 10. Then I did a for loop so that it should parse the number from the textbox into the array. But when I run nothing happens. (or as far as Im concerned its working I just havent displayed it back to see if its storing the numbers)
1) Am I doing this correctly for this situation? 2) Since I need to display the contents of the array once its populated via a button, would my variables need to be global?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace array
{
public partial class array : Form
{
public array()
{
InitializeComponent();
}
private void exitBtn_Click(object sender, EventArgs e)
{
this.Close();
}
public void addValBtn_Click(object sender, EventArgs e)
{
double[] numArray = new double[10];
for (int index = 0; index < numArray.Length; index++)
{
numArray[index] = int.Parse(intTxtBox.Text);
}
}
private void displayValBtn_Click(object sender, EventArgs e)
{
}
}
}