C# Convert ToString(Object, IFormatProvider)
Description
Convert ToString(Object, IFormatProvider)
converts
the value of the specified object to its equivalent string representation
using the specified culture-specific formatting information.
Syntax
Convert.ToString(Object, IFormatProvider)
has the following syntax.
public static string ToString(
Object value,
IFormatProvider provider
)
Parameters
Convert.ToString(Object, IFormatProvider)
has the following parameters.
value
- An object that supplies the value to convert, or null.provider
- An object that supplies culture-specific formatting information.
Returns
Convert.ToString(Object, IFormatProvider)
method returns The string representation of value, or String.Empty if value is null.
Example
using System;//w ww.j a v a 2 s. co m
using System.Globalization;
class MainClass
{
public static void Main( )
{
NumberFormatInfo provider = new NumberFormatInfo();
provider.NegativeSign = "neg ";
provider.PositiveSign = "pos ";
provider.NumberDecimalSeparator = ".";
provider.NumberGroupSeparator = ",";
provider.NumberGroupSizes = new int[ ] { 3 };
provider.NumberNegativePattern = 0;
Console.WriteLine( Convert.ToString((object) "12345" ));
Console.WriteLine( Convert.ToString((object) "12345", provider ) );
}
}
The code above generates the following result.