Convert.ToByte(String, IFormatProvider) Method in C#

CsharpServer Side ProgrammingProgramming

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.


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.


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);


This will produce the following output −

Converted byte value...
Published on 06-Nov-2019 10:45:52