I have this working almost as intended. The program it self is functional but the output is kinda screwy. It requires multiple hits of of the return key in order to display the contents of the array which is in a for loop and being called by the output() method.
=( seems like a simple enough thing but I am not seeing my problem.
My second issue is the fact that I call output(arr) ONCE but the output prints multiple instances of the array based on the size of the array….
class Program
{
static void Main(string[] args)
{
int value;
Console.Write("How big of an Array? ");
int arraySize = int.Parse(Console.ReadLine());
int[] arr = new int[arraySize];
for (int i = 0; i <= arraySize - 1; i++)
{
Console.Write("First Value: ");
value = int.Parse(Console.ReadLine());
arr[i] = Convert.ToInt32(value);
}
output(arr);
Console.ReadLine();
}
static void output(Array arr)
{
foreach (int i in arr)
{
for (int v = 0; v < arr.Length; v++)
{
string number = "Value: ";
string arrayPoint = "Array Section: ";
Console.WriteLine("{0}{1}\t{2}{3}", arrayPoint, v, number, i);
}
}
}
}
Couple of things in your code,
Your output method is receiving parameter of type
Array, instead it should be receivingint[], and you should loop it once, not twice.2nd, in your Main method you are using the prompt Enter First Value, which is somewhat confusing when the user is suppose to enter the value for the 2nd or later elements, you may change it to: