This is never going to work:
Array = "gdgd";
That's trying to assign a string
value to a string[]
property. Note that you can't add or remove elements in an array anyway, as once they've been created the size is fixed. Perhaps you should use a List<string>
instead:
public partial class Form1 : Form
{
List<string> list = new List<string> {
"just", "putting", "something", "inside", "the", "list"
};
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
List.Add("gdgd");
}
public List<string> List
{
get { return list; }
set { list = value; }
}
}
Note that having the public property is irrelevant here anyway, as you're accessing it from within the same class - you can just use the field:
private void button1_Click(object sender, EventArgs e)
{
list.Add("gdgd");
}
Also note that for "trivial" properties like this you can use an automatically implemented property:
public partial class Form1 : Form
{
public List<string> List { get; set; }
public Form1()
{
InitializeComponent();
List = new List<string> {
"just", "putting", "something", "inside", "the", "list"
};
}
private void button1_Click(object sender, EventArgs e)
{
List.Add("gdgd");
}
}