I would like to insert the user input into an array when the user clicks the submit button. This is what I wrote but it doesnt seem to work. The form is called form1 and it is its own class, the textbox is textbox1. Note: I am a newbie in programming.
//This is my array
private string[] texts = new string[10];
public string[] Texts
{
get { return texts; }
set { texts = value; }
}
//I then attempt to insert the value of the field into the textbox
form1 enterDetails = new form1();
for(int counter = 0; counter<Texts.Length; counter++)
{
texts[counter]=enterDetails.textbox1.Text;
}
You have done some silly mistakes here:
In setter of Texts property you should say
instead of
guestNames = value;
You don't need to create a new instance of your form1 as all the code you written above is already inside the form1 class. If not then try to get the same instance of form1.
Not necessary but you should set your property not the field.
Replace
with
So, your complete code should look like: