C#의 Char.TryParse() 메서드는 지정된 문자열의 값을 해당하는 유니코드 문자로 변환하는 데 사용됩니다.
구문
public static bool TryParse (string str, out char res);
이제 Char.TryParse() 메서드를 구현하는 예를 살펴보겠습니다. -
예시
using System;
public class Demo {
public static void Main(){
bool res;
Char ch;
res = Char.TryParse("10", out ch);
Console.WriteLine(res);
Console.WriteLine(ch.ToString());
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
False
이제 다른 예를 살펴보겠습니다 -
예시
using System;
public class Demo {
public static void Main(){
bool res;
Char ch;
res = Char.TryParse("P", out ch);
Console.WriteLine(res);
Console.WriteLine(ch.ToString());
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
True P