It is necessary to display all the numbers from the ListBox in the Label. How do I do multiple checks?

int index = listBox1.SelectedIndex; string str = (string)listBox1.Items[index]; int len = str.Length; int i = 0; while (i < len) { if (str[i] == //Здесь должны быть несколько вариантов для проверки, как: '1', '2', и т.д. } 
  • Please fix your question to russian only text. You need to make it clear. Please remove all English text from the question. And also give a clearer description of what you want to get - Andrew
  • You are still on RuSO, which means English is not appropriate here. Regarding the question - check on the array / collection, method Contains , or LINQ Any . - EvgeniyZ

1 answer 1

If I understand correctly what I need to get ... It will be something like this:

 string str = (string)listBox1.Item[0]; label1.Text = new String(str.Where(Char.IsDigit).ToArray()); 
  • Thank. I would be happy to check, but, for some reason, despite the fact that I added a line to the listbox, the debugging is covered, indicating that "ListBox was null". And what to do - I do not know. - Maniron Rafnrun
  • because the code is executed before you select the element in listBox1 - Andrew
  • The item is added from the start. And the code that you gave, I tied a button. And, in fact, he should highlight the element in the form, and after I select it and press the button, the number of digits will be highlighted in the Label. - Maniron Rafnrun
  • added does not mean allocated. Now I'll fix it. - Andrew