Free mag vol1 | Page 204

CHAPTER 4  CORE C# PROGRAMMING CONSTRUCTS, PART II static void SystemArrayFunctionality() { Console.WriteLine("=> Working with System.Array."); // Initialize items at startup. string[] gothicBands = {"Tones on Tail", "Bauhaus", "Sisters of Mercy"}; // Print out names in declared order. Console.WriteLine("-> Here is the array:"); for (int i = 0; i < gothicBands.Length; i++) { // Print a name. Console.Write(gothicBands[i] + ", "); } Console.WriteLine("\n"); // Reverse them... Array.Reverse(gothicBands); Console.WriteLine("-> The reversed array"); // ... and print them. for (int i = 0; i < gothicBands.Length; i++) { // Print a name. Console.Write(gothicBands[i] + ", "); } Console.WriteLine("\n"); } // Clear out all but the final member. Console.WriteLine("-> Cleared out all but one..."); Array.Clear(gothicBands, 1, 2); for (int i = 0; i < gothicBands.Length; i++) { // Print a name. Console.Write(gothicBands[i] + ", "); } Console.WriteLine(); If you invoke this method from within Main(), you will get the output shown here: => Working with System.Array. -> Here is the array: Tones on Tail, Bauhaus, Sisters of Mercy, -> The reversed array Sisters of Mercy, Bauhaus, Tones on Tail, -> Cleared out all but one... Sisters of Mercy, , , 139