The Convert.ToByte() method in C# converts the specified string representation of a number to an equivalent 8-bit unsigned integer, using specified culture-specific formatting information.
Syntax
Following is the syntax −
public static byte ToByte (string val, IFormatProvider provider);
Above, Val is a string that contains the number to convert. A parameter provider is an object that supplies culture-specific formatting information.
Example
Let us now see an example to implement the Convert.ToByte() method −
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);
}
}Output
This will produce the following output −
Converted byte value... 5