I have such a problem.
I sorted all the numbers in the list and printed them in the listBox. I read the numbers from the txt file which I make an array.
I need the user to type in any number (which I kept in the variable "a") those numbers in the following order:
- first the numbers less than a
- then the numbers equal to a
- and finally the big numbers.
and print it all in listBox.
...
float x;
if (float.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out x))
{
lst.Items.Add(x);
}
List<float> array = new List<float>();
array.Add(x);
a = Convert.ToInt32(txt1.Text);
int at = lst2.Items.Count;
for (int o = 0; o < lst2.Items.Count; ++o)
{
if (x < (float)(lst2.Items[o]) && a >= o)
{
at = o;
break;
}
}
lst2.Items.Insert(at, x);
With this code I only sort the numbers without sorting with a variable.