สมมติว่าต่อไปนี้คือสตริง −
Welcome
หลังจากย้อนกลับสตริงแล้ว คำควรจะมองเห็นได้เช่น −
emocleW
ใช้วิธีการ reverse() และลองใช้รหัสต่อไปนี้เพื่อย้อนกลับคำในสตริง -
ตัวอย่าง
using System;
using System.Linq;
class Demo {
static void Main() {
string str = "Welcome";
// reverse the string
string res = string.Join(" ", str.Split(' ').Select(s => new String(s.Reverse().ToArray())));
Console.WriteLine(res);
}
}