C# Convert ToInt32(String, IFormatProvider)
Description
Convert ToInt32(String, IFormatProvider)
converts
the specified string representation of a number to an equivalent 32-bit
signed integer, using the specified culture-specific formatting information.
Syntax
Convert.ToInt32(String, IFormatProvider)
has the following syntax.
public static int ToInt32(
string value,
IFormatProvider provider
)
Parameters
Convert.ToInt32(String, IFormatProvider)
has the following parameters.
value
- A string that contains the number to convert.provider
- An object that supplies culture-specific formatting information.
Returns
Convert.ToInt32(String, IFormatProvider)
method returns A 32-bit signed integer that is equivalent to the number in value, or 0 (zero)
if value is null.
Example
using System;/*from w w w . j a v a 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( "12345" ));
Console.WriteLine( Convert.ToInt32( "12345", provider ) );
}
}
The code above generates the following result.