
要反转一个字符串,使用 Array.Reverse() 方法。
设置要反转的字符串 −
string str = "Amit";
在上述方法中,我们将字符串转换为字符数组 −
char[] ch = str.ToCharArray();
然后使用Reverse()方法。
Array.Reverse(ch);
Example
的中文翻译为:示例
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
string str = "Amit";
char[] ch = str.ToCharArray();
Array.Reverse(ch);
foreach(var items in ch) {
Console.WriteLine(items);
}
Console.ReadLine();
}
}
} 