I do not have much experience with C # and Forms but I have a problem with static variables. I need a static int variable to define the size of a static array.
Public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
cont(Box.Text);
}
static int c = 0;
static string[] elementos = new string[c+1];
static void cont(string var1)
{
elementos[c]= var1;
MessageBox.Show(elementos[c]);
c += 1;
}
}
I need the static "int c = 0" to work as the array size "static string [] elements = new string [c +1]" but throws the following error "Index outside the boundaries of the array."
How do I get one static variable to work with another variable?