I have this code that uses three methods to do certain tasks. One creates an array, another reverses it and the other one prints it out(it was required to use three methods). A person recommended me to upload my code here as there are a few things that need to be improved.
They said that I do not need to return arrays if I modify them in-place, and GenerateNum
could allocate the array itself instead of requiring an array with the correct size to be passed. However as a beginner I didn't quite catch what they were trying to tell me to change in the code.
using System;
class Program
{
static void Main(string[] args)
{
string getnums = Console.ReadLine();
int getnum = Convert.ToInt32(getnums);
int[] array1 = new int[getnum];
GenerateNum(getnum,array1);
RevArray(array1);
PrintArray(array1);
}
static int[] GenerateNum(int getnums, int[] arrayy)
{
for (int index = 0; index < getnums; index++)
{
arrayy[index] = index;
}
return arrayy;
}
static int[] RevArray(int[] arrayy)
{
for (int index = 0; index < (arrayy.Length)/2; index++)
{
int a = arrayy[index];
arrayy[index] = arrayy[arrayy.Length - index-1];
arrayy[arrayy.Length-index-1] = a;
}
return arrayy;
}
static void PrintArray(int[] arrayy)
{
Console.WriteLine(string.Join(",",arrayy));
}
}