Tekleri - çiftleri çıkart

 avatar
unknown
csharp
a year ago
1.4 kB
4
Indexable
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));



}


int[] sayi = new int[10];
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    
    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]);
    }
}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
    if(comboBox1.SelectedIndex == 1)
    {
        listBox1.Items.Clear();
        for (int i = 0; i < 10; i++)
            if (sayi[i] % 2 == 0)
                listBox1.Items.Remove(sayi[i]);
    }
    else if(comboBox1.SelectedIndex == 0)
    {
        listBox1.Items.Clear();
        for (int i = 0; i < 10; i++)
            if (sayi[i] % 2 == 1)
                listBox1.Items.Remove(sayi[i]);
    }
}
Leave a Comment