Sıralamalı falan liste

mail@pastecode.io avatar
unknown
csharp
2 months ago
896 B
2
Indexable
Never
private void button1_Click(object sender, EventArgs e)
{
    int sayi1 = int.Parse(textBox1.Text);
    int sayi2 = int.Parse(textBox2.Text);
    Random rand = new Random();
    for (int i = 0; i < 10; i++)
        listBox1.Items.Add(rand.Next(sayi1, sayi2));
    
    

}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    int[] sayi = new int[10];
    for (int i = 0;i < listBox1.Items.Count;i++)
            sayi[i] = int.Parse(listBox1.Items[i].ToString());
    listBox1.Items.Clear();
    
    if (comboBox1.SelectedIndex == 1)
    {
        Array.Sort(sayi);
        Array.Reverse(sayi);
        for(int i = 0; i < 10; i++)
            listBox1.Items.Add(sayi[i]);
    }
    else if (comboBox1.SelectedIndex == 0)
    {
        Array.Sort(sayi);
        for (int i = 0; i < 10; i++)
            listBox1.Items.Add(sayi[i]);
    }
}
Leave a Comment