Phương thức Char.Parse(String) trong C# chuyển đổi giá trị chuỗi được chỉ định thành ký tự Unicode tương đương.
Cú pháp
public static char Parse(string str);
Tham số str là chuỗi chứa một ký tự hoặc null.
Ví dụ 1
using System;
public class Demo
{
public static void Main()
{
string str = "a";
char res = Char.Parse(str);
Console.WriteLine("Value = " + str);
Console.WriteLine("Equivalent Unicode character = " + res);
}
}
Đầu ra
Value = a Equivalent Unicode character = a
Ví dụ 2
using System;
public class Demo
{
public static void Main()
{
string str = "#";
char res = Char.Parse(str);
Console.WriteLine("Value = " + str);
Console.WriteLine("Equivalent Unicode character = " + res);
}
}
Đầu ra
Value = # Equivalent Unicode character = #