Phương thức Convert.ToByte() trong C# chuyển đổi biểu diễn chuỗi của số thành số nguyên không dấu 8-bit tương đương, sử dụng thông tin định dạng theo culture cụ thể.
Cú pháp
public static byte ToByte(string val, IFormatProvider provider);
Tham số val là chuỗi chứa số. provider cung cấp thông tin định dạng theo culture.
Ví dụ
using System;
using System.Globalization;
public class Demo
{
public static void Main()
{
CultureInfo cultures = new CultureInfo("en-US");
String str = "5";
Console.WriteLine("Converted byte value...");
byte res = Convert.ToByte(str, cultures);
Console.Write("{0}", res);
}
}
Đầu ra
Converted byte value... 5