int[] numbers = { 1, 2, 3, 4, 5 }; Array.Reverse(numbers); // numbers is now { 5, 4, 3, 2, 1 }
Listwords = new List { "hello", "world", "goodbye", "cruel", "world" }; words.Reverse(); // words is now { "world", "cruel", "goodbye", "world", "hello" }
string message = "Hello world!"; char[] chars = message.ToCharArray(); Array.Reverse(chars, 0, 5); message = new string(chars); // message is now "olleH world!"In each example, we are using a method from the System Reverse package library, which can be found in the System namespace.