I am new to C# and I am trying to sort numbers from lowest to highest and then put them inside a ListBox
. What I did so far is:
{
int[] sortArray = new int[listBox2.Items.Count];
for (int i = 0; i < listBox2.Items.Count; i++)
{
string sort = listBox2.GetItemText(i);
sortArray[i] = int.Parse(sort);
}
int aantal = listBox2.Items.Count;
listBox2.Items.Clear();
Array.Sort(sortArray);
listBox2.Items.Add(sortArray);
}
There are some numbers in the ListBox
and when you press the button it should sort them. Can someone tell me what I do wrong?
I found the answer, this is what I had to do. Thanks for your help :)