-1

How do you reverse the list in order to display A-Z in reverse from "ZYX....A" I tried to create the ReverseAlpha method but I'm not sure what to do from there.

static void Main(string[] args) {
    //variable declarations
    const int SIZE = 26;
    char[]
    alpha = new char[SIZE];
    //function calls
    FillAlpha(alpha);
    Console.WriteLine("Print Original List A-Z:");
    PrintAlpha(alpha);
    ReverseAlpha(alpha);
    Console.WriteLine("\nPrint Reversed List Z-A:");
    PrintAlpha(alpha);
    Console.Write("\n\nPress any key to continue:");
    Console.ReadKey();
}

static void FillAlpha(char[] letters) {
    for (int i = 0; i < 26; i++) {
        letters[i] = (char)(i + 65);
    }
}

static void PrintAlpha(char[] letters) {
    foreach(char c in letters)
    Console.Write(c + " ");
    Console.WriteLine();
}

static void ReverseAlpha(char[] letters) {
    char a, b, temp;
    temp = a;
    a = b;
    b = temp:
}
5
  • 1
    Imagine you have 10 boxes in a row in front of you. How would you reorder the contents of those boxes so that it was in reverse order after you complete? Commented Dec 14, 2017 at 1:33
  • 2
    Your ReverseAlpha function doesn't do anything. You should try harder. Commented Dec 14, 2017 at 1:40
  • More importantly, your ReverseAlpha method doesn't even compile. Make sure your code actually compiles first. Commented Dec 14, 2017 at 2:12
  • Possible duplicate of Reverse an array without using Array.Reverse() Commented Dec 14, 2017 at 2:52
  • It would probably be better to give your methods more meaningful names. You have a variable named alpha, which happens to be a char array, but your methods will work on any array so consider leaving Alpha out of the method names, and instead do something like static void FillArray(char[] input, int size) Commented Dec 14, 2017 at 2:55

1 Answer 1

1

https://msdn.microsoft.com/en-us/library/d3877932(v=vs.110).aspx

    static char[] ReverseAlpha(char[] letters)
    {
        letters = letters.Reverse().ToArray(); 
        return letters;
    }
Sign up to request clarification or add additional context in comments.

3 Comments

You reference array.Reverse(), but your code is using System.Linq
actually, I was wrong - calling letters.Reverse(); does reverse the original array. Sorry!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.