C# Convert ToInt32(Object, IFormatProvider)
Description
Convert ToInt32(Object, IFormatProvider)
converts
the value of the specified object to a 32-bit signed integer, using the specified
culture-specific formatting information.
Syntax
Convert.ToInt32(Object, IFormatProvider)
has the following syntax.
public static int ToInt32(
Object value,
IFormatProvider provider
)
Parameters
Convert.ToInt32(Object, IFormatProvider)
has the following parameters.
value
- An object that implements the IConvertible interface.provider
- An object that supplies culture-specific formatting information.
Returns
Convert.ToInt32(Object, IFormatProvider)
method returns A 32-bit signed integer that is equivalent to value, or zero if value is null.
Example
using System;/*from ww w .java 2 s .c o 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.ToInt32((object) "12345" ));
Console.WriteLine( Convert.ToInt32((object) "12345", provider ) );
}
}
The code above generates the following result.