1

I am very new to coding and have been asked to do the following: Create two static arrays that will hold the gross and net income. A user will input the gross income every month and the net must be calculated and saved.

Now what iv have so far is this:

public partial class Form1 : Form
{
    public static double[] gross { get; set; }
    public static double[] net { get; set; }

    public Form1()
    {
        InitializeComponent();
    }

    private void btnEnter_Click(object sender, EventArgs e)
    {
        Gross g = new Gross();
        g.ShowDialog();
        gross = new double[] { g.grossTemp };
        net = new double[] { g.netin };
    }        
}

But every time i want to add a new gross and net income, it replaces the old one instead of adding the new one to a new index. I think the problem is because i'm creating a new instance but i don't know what else to do.

tshepang
  • 12,111
  • 21
  • 91
  • 136
toddler dev
  • 21
  • 2
  • 8

1 Answers1

0

You can use List as a private type , and the public type can remain an array like this :

public static double[] gross  get { return  _gross.ToArray()    }

private static List<double> _gross;


private void btnEnter_Click(object sender, EventArgs e)
{
    Gross g = new Gross();
    g.ShowDialog();
    _gross.Add(g.grossTemp );
}        
Shachaf.Gortler
  • 5,655
  • 14
  • 43
  • 71