I am trying to create a static global array called “series”. But the number of strings inside it should depend on a nummericUpDown counter. I have tried a lot of variations, resulting in a lot of error variations. My code looks like this, near the top of my code i have:
public partial class Form1 : Form
{
static string[] series;
So after i have made the array global with that i want to set its size.
As a nummericUpDown can go up and down, i erase array first (causing errors)
Later i want to fill it with { “M1″,”M2″,”M3” ……etc}
How should i write this code that it will work ?
private void numericUpDown1_ValueChanged_1(object sender, EventArgs e)
{
if (numericUpDown1.Value < 1) { numericUpDown1.Value = 1; }
int i;
series[0] = "x";
if (series.Length > 0) { Array.Clear(series, 0, series.Length); }
for (i = 0; i < numericUpDown1.Value; i++) { series[i] = "M" + i.ToString(); }
}
You just need to set your series variable to a new array of the correct size. Doing so will clear all previous values that were in the array before.