Q: C# Empty array not accepting input What I'm attempting to do is enter data into the empty arrays using a form textbox.  The form will display the first array(values are already entered), but it will not accept the values that entering into the textbox.  No matter what value I enter, it posts $0.00 in the whole row.  It won't even take in a name(string).  Can anyone guide me in the right direction.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WP_Week3_Part1
{
    public partial class ArrayForm : Form
    {
        int[] deptArray = new int[5] { 1, 2, 3, 4, 5 };
        double[] contArray = new double[5] { 0, 0, 0, 0, 0};
        string[] nameArray = new string[5] { "", "", "", "", "" };
        public ArrayForm()
        {
            InitializeComponent();
        }

        private void buttonValue_Click(object sender, EventArgs e)
        {
            int dept;
            dept = Convert.ToInt32(textBoxDept.Text);
            double cont;
            cont = Convert.ToDouble(textBoxCont.Text);
            textBoxDept.Text = "";
            textBoxCont.Text = "";
            textBoxDonor.Text = "";
            labelOutput.Text = "Printing Contribution Table \n dept          amount          donor";
            for (int i = 0; i < deptArray.Length; i = i + 1)
            {
                nameArray[i] = textBoxDonor.Text;
                labelOutput.Text += String.Format("\n {0}          {1}          {2} ", deptArray[i], contArray[i].ToString("C"), nameArray[i]);
            }

        }
    }
}


A: You have two problems:


*

*You get the cont value and then do nothing with it. You print contArray[i] but that is not assigned after being initialized to 0, so of course it always prints 0. Not sure what the logic is supposed to be based on your code, but either print cont or assign the array member(s).

*You clear the donor text box (textBoxDoneor.Text = "") before using it in the for loop. So when you assign the element of nameArray, you are always assigning the empty string. You also always assign every member of the array, not sure if that is intentional or you just haven't gotten that far with your program yet.

A: It returns $0.00 because:
You set your text textBoxDonor to empty
it should be like this:
            int dept;
            dept = Convert.ToInt32(textBoxDept.Text);
            double cont;
            cont = Convert.ToDouble(textBoxCont.Text);
            //textBoxDept.Text = "";
            //textBoxCont.Text = "";
            //textBoxDonor.Text = "";
            labelOutput.Text = "Printing Contribution Table \n dept          amount          donor";
            for (int i = 0; i < deptArray.Length; i = i + 1)
            {
                nameArray[i] = textBoxDonor.Text;
                labelOutput.Text += String.Format("\n {0}          {1}          {2} ", deptArray[i], contArray[i].ToString("C"), nameArray[i]);


     }

Checking the content of your nameArray right after the execution
        string arrlist = string.Empty;
        foreach (var arr in nameArray.ToList())
        { 
           arrlist = arrlist +' ' + arr.ToString();
        }
        MessageBox.Show(arrlist);

