C#中的Char.TryParse()方法
C#中的Char.TryParse()方法用于将指定字符串的值转换为其等效的Unicode字符。
语法
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