Answer the question
In order to leave comments, you need to log in
How to make an array with listBox1.SelectedItem?
tell me how to make an array with listBox1.SelectedItem?
I have an input file
that opens in listBox1 I need to take 1 line and find out the number of the maximum element
a line of type * Experiment_49 -243.00 -239.23 -228.04 -209.77 -184.98 -154.41 -119, 00 -79.82 -38.06 5.00 48.06 89.82 129.00 164.41 194.98 219.77
I remove * Experiment_49
string Str1 = listBox1.SelectedItem.ToString();
string Str2 = Str1.Substring(17);
Answer the question
In order to leave comments, you need to log in
// получаем строку с элементами
string Str1 = listBox1.SelectedItem.ToString();
// разделяем строку в массив строк по символу "пробел"
var strings = Str1.Split(' ');
// Преобразуем все строки в числа
var items = strings.Select(double.Parse);
// Находим максимальный элемент
var max = items.Max();
// Ищем индекс максимального элемента
var maxIndex = Array.IndexOf(items, max);
// Можно сократить запись:
string Str = listBox1.SelectedItem.ToString();
var items = Str.Split(' ').Select(double.Parse).ToArray();
var maxIndex = Array.IndexOf(items, items.Max());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question