System.Int32.Parse Method

Converts the string representation of a number in a specified culture-specific format to its 32-bit signed integer equivalent.


public static int Parse (string s, IFormatProvider provider)


A string containing a number to convert.
An object that supplies culture-specific formatting information about s.


A 32-bit signed integer equivalent to the number specified in s.


ArgumentNullException s is a null reference.
FormatException s is not in the correct style.
OverflowException s represents a number greater than int.MaxValue or less than int.MinValue.


This overload of the int.Parse(string, IFormatProvider) method is typically used to convert text that can be formatted in a variety of ways to an int value. For example, it can be used to convert the text entered by a user into an HTML text box to a numeric value.

The s parameter contains a number of the form:


Items in square brackets ([ and ]) are optional. The following table describes each element.


Optional white space.


An optional sign.


A sequence of digits ranging from 0 to 9.

The s parameter is interpreted using the System.Globalization.NumberStyles.Integer style. In addition to decimal digits, only leading and trailing spaces together with a leading sign are allowed. To explicitly define the style elements that can be present in s, use the int.Parse(string, System.Globalization.NumberStyles, IFormatProvider) method.

The provider parameter is an IFormatProvider implementation, such as a System.Globalization.NumberFormatInfo or System.Globalization.CultureInfo object. The provider parameter supplies culture-specific information about the format of s. If provider is null, the System.Globalization.NumberFormatInfo object for the current culture is used.


Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0,,