Reputation: 73
I am using TextChanged event and when I am pressing keyboard, numbers are going into array... the question is: When I am deleting any numbers I want to delete in the array list too but cause of textchange event I already added an element I just want to delete the element and add another element
How do I do this?
long i;
long[] array1 = new long[11];
private void textBox1_TextChanged(object sender, EventArgs e)
{
try
{
array1[i] = long.Parse(textBox1.Text) % 10;
//MessageBox.Show(array1[i].ToString());
}
catch
{
if (i > 10)
{
//MessageBox.Show("it can be bigger than 11");
}
}
i++;
}
Upvotes: 1
Views: 112
Reputation: 94645
You can't remove an element from the list. Use List<T>
collection.
List<long> list=new List<long>();
list.Add(100);
list.Add(200);
//To remove a number
list.Remove(100);
EDIT:
You may separate each digit of input text (Add textBox1 and listBox1 control):
int[] ar;
private void textBox1_TextChanged(object sender, EventArgs e)
{
ar = textBox1.Text.Select(p => p - 48).ToArray();
listBox1.DataSource = ar;
}
Upvotes: 1