So, like the title says I need to pull the min and max values from an array I’ve created that utilizes a random number generator to fill it. I get the feeling it’s probably the Math class of operators that I need to use (IE, the math.floor and math.ceiling) but if that’s so I’m not quite sure how to utilize them with the array. I suppose the bottom line is that I don’t quite understand how arrays work, even though I’ve already done a couple of assignments utilizing them. Here’s what I have so far (I have to display all values in the listbox and give average and min/max for this assignment)
private void button1_Click(object sender, EventArgs e)
{
int SIZE = 10;
int[] nummers = new int[SIZE];
Random rand = new Random();
int total = 0;
for (int index = 0; index < nummers.Length; index++)
{
nummers[index] = rand.Next(1, 100);
}
foreach (int value in nummers)
{
total += value;
listBox1.Items.Add(value);
}
total/= 10;
label3.Text = total.ToString("d");
You can use Linq to make your life easier:
Old style:
modify the foreach to be like this: