다음이 문자열이라고 가정해 봅시다 -
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);
}
}