The Char.TryParse() method in C# is used to convert the value of the specified string to its equivalent Unicode character.
Syntax
public static bool TryParse (string str, out char res);
Let us now see an example to implement the Char.TryParse () method −
Example
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());
}
}Output
This will produce the following output −
False
Let us now see another example −
Example
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());
}
}Output
This will produce the following output −
True P