i'm beginner at c# and programming in total.. so i'm working on this code in school right now, where i have to generate 21 random numbers between 1-21 (you can have duplicates of numbers). i have made the code and it's working sorta... it generates the numbers in listbox1 but it's not the same numbers i get sorted in listbox3.
private void button1_Click(object sender, EventArgs e)
{
int[] a = new int[21];
Random tal = new Random();
for (int x = 1; x < a.Length; x++)
{
a[x] = tal.Next(1, 21);
}
for (int x = 1; x < a.Length; x++)
{
listBox1.Items.Add(a[x]);
}
foreach (int i in a)
{
Array.Sort(a);
listBox3.Items.Add(a[i]);
}
int min = a[1];
for (int x = 1; x < a.Length; x++)
if (a[x] < min)
min = a[x];
listBox2.Items.Add(min);
int max = a[20];
for (int x = 1; x > a.Length; x++)
if (a[x] < max)
max = a[x];
listBox2.Items.Add(max);
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
int[] a = new int[21];
Random tal = new Random();
a.Clone();
foreach (int i in a)
{
Array.Sort(a);
listBox3.Items.Add(a[i]);
}
}
}
}