C# | Byte.ToString Method | Set - 1
Last Updated :
05 Dec, 2019
This method is used to convert the value of the current Byte object to its equivalent string representation. There are total 4 methods in the overload list of
Byte.ToString() Method as follows:
- ToString(IFormatProvider)
- ToString(String, IFormatProvider)
- ToString()
- ToString(String)
ToString(IFormatProvider)
This method is used to Converts the numeric value of the current Byte object to its equivalent string representation using the specified culture-specific formatting information.
Syntax:
public string ToString (IFormatProvider provider);
Parameters: This method takes an object of type
IFormatProvider that supplies culture-specific formatting information.
Return Value: This method returns the string representation of the value of this object in the format specified by the provider parameter.
Below programs illustrate the use of
Byte.ToString(IFormatProvider) Method:
Example 1:
csharp
// C# program to demonstrate
// Byte.ToString(IFormatProvider)
// Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// declaring and initializing bytevalue
byte byteValue = 15;
// creating and initializing
// the object of CultureInfo
CultureInfo provider = new CultureInfo("en-us");
// getting the value
// using ToString()
string value = byteValue.ToString(provider);
// Display the value
Console.WriteLine("value is {0} and provider is {1}",
value, provider.Name);
}
}
Output:
value is 15 and provider is en-US
Byte.ToString(String, IFormatProvider) Method
This method is used to convert the value of the current Byte object to its equivalent string representation using the specified format and culture-specific formatting information.
Syntax:
public string ToString (string format, IFormatProvider provider);
Parameters:
format: It is a standard or custom numeric format string.
provider: It is an object that supplies culture-specific formatting information.
Return Value: This method returns the string representation of the value of this object in the format specified by the provider parameter.
Exceptions: This method will give
FormatException if the format includes an unsupported specifier.
Below programs illustrate the use of
Byte.ToString(String, IFormatProvider) Method:
Example 1:
csharp
// C# program to demonstrate the
// Byte.ToString(String, IFormatProvider)
// Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// declaring and initializing bytevalue
byte byteValue = 15;
// creating and initializing
// the object of CultureInfo
CultureInfo provider = new CultureInfo("fr-FR");
// declaring and initializing format
string format = "D5";
// getting the value
// using ToString()
string value = byteValue.ToString(format, provider);
// Display the value
Console.WriteLine("value is {0} and provider is {1}",
value, provider.Name);
}
}
Output:
value is 00015 and provider is fr-FR
Example 2: For
FormatException
csharp
// C# program to demonstrate the
// Byte.ToString(String, IFormatProvider)
// Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
try {
// declaring and initializing bytevalue
byte byteValue = 15;
// creating and initializing
// the object of CultureInfo
CultureInfo provider = new CultureInfo("fr-FR");
// declaring and initializing format
string format = "s5";
// getting the value
// using ToString()
Console.WriteLine("format is invalid");
string value = byteValue.ToString(format, provider);
// Display the value
Console.WriteLine("value is {0} and provider is {1}",
value, provider.Name);
}
catch (FormatException e) {
Console.Write("Exception Thrown: ");
Console.Write("{0}", e.GetType(), e.Message);
}
}
}
Output:
format is invalid
Exception Thrown: System.FormatException
Byte.ToString() Method
This method is used to convert the value of the current Byte object to its equivalent string representation.
Syntax:
public override string ToString ();
Return Value: This method returns the string representation of the value of this object, which consists of a sequence of digits that range from 0 to 9 with no leading zeroes.
Below programs illustrate the use of
Byte.ToString() Method:
Example 1:
csharp
// C# program to demonstrate
// Byte.ToString() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// declaring and initializing bytevalue
byte byteValue = 15;
// getting the value
// using ToString()
string value = byteValue.ToString();
// Display the value
Console.WriteLine("value is {0} ", value);
}
}
Reference:
Similar Reads
C# | Double.ToString() Method | Set - 1
Double.ToString() Method is used to convert the numeric value of the current instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: ToString(String) Method ToString() Method ToString(IFormatProvider) Method ToString(String, IFormatProvid
3 min read
C# | Int64.ToString Method | Set - 1
Int64.ToString Method is used to convert the numeric value of the current instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: ToString(IFormatProvider) MethodToString(String, IFormatProvider) MethodToString( ) MethodToString(String) M
2 min read
C# | Int32.ToString Method | Set - 1
Int32.ToString Method is used to converts the numeric value of the current Int32 instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows:Here, we will discuss the first two methods. ToString(IFormatProvider) Method This method is used to c
2 min read
C# | Decimal.ToString Method | Set -1
Decimal.ToString() Method is used to convert the numeric value of the current instance to its equivalent string representation using the specified culture-specific format information. There are 4 methods in the overload list of this method as follows: ToString() Method ToString(IFormatProvider) Meth
3 min read
C# | Int16.ToString Method | Set - 1
Int16.ToString Method is used to convert the numeric value of the current instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: ToString(IFormatProvider) Method ToString(String, IFormatProvider) Method ToString() Method ToString(String)
2 min read
C# | Decimal.ToString Method | Set -2
Decimal.ToString() Method is used to convert the numeric value of the current instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: ToString(String) Method ToString() Method ToString(IFormatProvider) Method ToString(String, IFormatProvi
2 min read
C# | Int64.ToString Method | Set - 2
Int64.ToString Method is used to convert the numeric value of the current instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: ToString(IFormatProvider) Method ToString(String, IFormatProvider) Method ToString() Method ToString(String)
2 min read
C# | Int32.ToString Method | Set - 2
Int32.ToString Method is used to convert the numeric value of the current instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: ToString(IFormatProvider) Method ToString(String, IFormatProvider) Method ToString() Method ToString(String)
2 min read
C# | Int16.ToString Method | Set - 2
Int16.ToString Method is used to convert the numeric value of the current instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: ToString(IFormatProvider) Method ToString(String, IFormatProvider) Method ToString() Method ToString(String)
2 min read
C# | Convert.ToBase64String() Method | Set-1
Convert.ToBase64String() Method is used to convert the value of an array of 8-bit unsigned integers to its equivalent string representation which is encoded with base-64 digits. There are 4 methods in the overload of this method which are as follows: ToBase64String(Byte[], Int32, Int32) Method ToBas
4 min read