I'm writing a program about reversing an array with 3 methods (GenerateNumber, reverse and PrintOut).
Unfortunately it doesn't run. Can you help me to find the error and fix them?
Why doesn't it run?
public class Program
{
static int[] GenerateNumber()
{
string a = Console.ReadLine();
int b = Convert.ToInt32(a);
int[] number = new int [b];
string[] c = new string[b];
for (int index = 0; index < number.Length; index++)
{
c[index] = Console.ReadLine();
number [index]= Convert.ToInt32(c[index]);
}
return number;
}
static int[] reverse(int[] array)
{
for (int index =0; index <array.Length; index++)
{
int c = array[index];
array[index] = array[array.Length - index - 1];
array[array.Length - index - 1]= c;
}
return array;
}
static int[] PrintOut (int[] array)
{
for (int index = 0; index > array.Length; index++)
Console.Write(array[index]);
return array;
}
static void Main(string[] args)
{
int[] number = GenerateNumber();
reverse(number);
PrintOut(number);
Console.ReadKey();
}
The immediate cause of the misbehaviour is in the
The comparison should be
<instead of>:A better choice, however, is
foreachloop instead offorSome suggestions: