char[] ch = "hello world!".ToCharArray();
Stack<char> s = new Stack<char>();
foreach (char c in ch) { s.Push(c); }
int idx = 0;
while (!s.IsEmpty) { ch[idx++] = s.Pop(); }
Console.WriteLine(new string(ch)); // !dlrow olleh
利用堆疊後進先出特性,將字元逐一壓入再彈出,達成字串反轉。