Write the following code in c #,In your main method use the method in question 1 to display the letters array, then use the Array.Reverse() method to reverse the letters array and then again call the appropriate method to print it
时间: 2024-01-17 18:06:00 浏览: 73
C# 字符串反转(两种方法)
Sure, here's the code:
```csharp
using System;
class Program
{
static void Main(string[] args)
{
char[] letters = {'a', 'b', 'c', 'd', 'e'};
PrintArray(letters);
Array.Reverse(letters);
PrintArray(letters);
}
static void PrintArray(char[] arr)
{
foreach(char c in arr)
{
Console.Write(c + " ");
}
Console.WriteLine();
}
}
```
This code first declares an array of characters and initializes it with the values 'a', 'b', 'c', 'd', and 'e'. Then it calls the `PrintArray` method to display the contents of the array. After that, it calls the `Array.Reverse` method to reverse the order of the elements in the array. Finally, it calls `PrintArray` again to display the reversed array.
阅读全文