using System;
using System.Windows.Forms;
namespace arrays_1
{
public partial class Form1 : Form
{
public string[] array1;
public ulong size = 0;
public string input = "";
public int counter = 0;
public Form1()
{
InitializeComponent();
array1 = new string[1];
}
public void btnImposta_Click() // defines array size
{
ulong size = Convert.ToUInt64(textBox_ArraySize.Text);
array1 = new string[size];
}
public void btnInserisciAggiungi_Click() // button to input in array
{
buttonInsertAdd.Text = "Add";
counter ;
input = textBox_Content.Text;
array1 = input; // Here's the error (I can't convert string "input" to string[] "array")
lstArray.Items.Add(array1[counter]);
textBox_Content.Clear();
}
}
}
Hi, as the title says, I'm trying to take the user input from a TextBox, put it in an Array and finally output it on a ListBox I don't know how to input the textbox text to the array, though.
Here's my code.
CodePudding user response:
A guy replied but the answer got deleted for some reason, writing
array1[counter] = input;
instead of
array1 = input;
fixed the problem.
CodePudding user response:
string[] enteredvalues = new string[0];
Array.Resize(ref enteredvalues, enteredvalues.Length 1);
enteredvalues[enteredvalues.Length - 1] = "string from textbox";