I need help with writing this code. This is the first time that I am working wit
ID: 3544163 • Letter: I
Question
I need help with writing this code. This is the first time that I am working with arrays.
Develop a C# console application that will work in MS Visual C# 2010 that implements an int array. Use 2 'for' loops, the first to fill the array using the Random class to generate random integers (see p241, section 7.9 - Dietel, 4th edition) using the next method of the Random class and a second for loop to iterate through the filled array and print the values entered into the array by the random number generator. Use the array
Explanation / Answer
using System;
namespace ConsoleApplication4
{
class myProgram
{
Random random = new Random();
public int getRandom()
{
return (int)this.random.Next(100, 1000);
}
static void Main(string[] args)
{
int randomValue;
myProgram myprogram = new myProgram();
int[] array = new int[10];
for (int i = 0; i < 10; i++)
{
array[i] = myprogram.getRandom();
}
for (int i = 0; i < 10; i++)
{
Console.WriteLine("The array value is {0}", array[i]);
}
Console.WriteLine("Press any key to continue . . .");
Console.ReadKey();
}
}
}