Combobox a rastgele sayı üretip bunların tek olanlarını listboxa atama






private void button2_Click(object sender, EventArgs e)
{
comboBox1.Items.Clear();
Random rnd = new Random();
int sayi = 0;
int[] dizi = new int[10];
int sayac = 0;
for (int i = 0; i < 10; i++)
{
sayi = rnd.Next(1, 15);
for (int a = 0; a < i; a++)
{
if (dizi[a] == sayi)
{
sayac++;
}
}
if (sayac == 0)
{
dizi[i] = sayi;
}
else
{
i--;
sayac = 0;
}
}
foreach (int x in dizi)
{
comboBox1.Items.Add(x);
}
}
-------------------------------------------------------------------
-------------------------------------------------------------------
private bool asalMi(int sayi)
{
if (sayi == 1)
{
return false;
}
for (int i = 2; i < sayi; i++)
{
if (sayi % i == 0)
{
return false;
}
}
return true;
}
private void button3_Click(object sender, EventArgs e)
{
int[] dizi = new int[comboBox1.Items.Count];
for (int i = 0; i < comboBox1.Items.Count; i++)
{
dizi[i] =Convert.ToInt32(comboBox1.Items[i]);
}
for (int a = 0; a < dizi.Length; a++)
{
if (asalMi(dizi[a]))
{
listBox1.Items.Add(dizi[a]);
}
}
}