Edit Recap - Reversed Array
Part of the Fundamentals section of Coddy's C# journey — lesson 60 of 69.
Challenge
EasyWrite a method named Reverse which gets an array of numbers as argument and returns the reversed array.
For example, for [1, 2, 3], the expected output is [3, 2, 1].
Note: Using Array.Reverse() is not allowed. Implement the reversal manually using a loop.
Hint: To access elements from the end of the array, use the index pattern arr.Length - 1 - i.
Try it yourself
using System;
public class Program {
public static int[] Reverse(int[] arr) {
// Write your code below
}
public static void Main(string[] args) {
string text = Console.ReadLine();
string[] stringArr = text.Split(",");
int[] arr = new int[stringArr.Length];
for (int i = 0; i < stringArr.Length; i++) {
arr[i] = int.Parse(stringArr[i]);
}
int[] result = Reverse(arr);
Console.WriteLine("The reversed array is: " + string.Join(", ", result));
}
}All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic Shortcuts5Operators Part 2
Comparison OperatorsLogical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 311Arrays Basics
Declaring ArraysAccessing ElementsModifying ArraysArray MethodsRecap - Product ArrayEdit Recap - Reversed Array