Converts the string representation of a number in a specified culture-specific format to its 8-bit signed integer equivalent.
- s
- A string that represents a number to convert. The string is interpreted using the System.Globalization.NumberStyles.Integer style.
- provider
- An object that supplies culture-specific formatting information about s. If provider is null, the thread current culture is used.
An 8-bit signed integer that is equivalent to the number specified in s.
Type Reason ArgumentNullException s is a null reference. FormatException s is not in the correct style. OverflowException s represents a number greater than sbyte.MaxValue or less than sbyte.MinValue.
The s parameter contains a number of the form:
[ws][sign]digits[ws]
Elements in square brackets ([ and ]) are optional. The following table describes each element.
ws |
Optional white space. |
sign |
An optional sign. |
digits |
A sequence of digits ranging from 0 to 9. |
The s parameter is interpreted using the System.Globalization.NumberStyles.Integer style. In addition to the byte value's decimal digits, only leading and trailing spaces with a leading sign are allowed. To explicitly define the style elements with the culture-specific formatting information that can be present in s, use the sbyte.Parse(string, System.Globalization.NumberStyles, IFormatProvider) method.
The provider parameter is an IFormatProvider implementation whose IFormatProvider.GetFormat(Type) method returns a System.Globalization.NumberFormatInfo object that provides culture-specific information about the format of s. There are three ways to use the provider parameter to supply custom formatting information to the parse operation:
You can pass the actual System.Globalization.NumberFormatInfo object that provides formatting information. (Its implementation of IFormatProvider.GetFormat(Type) simply returns itself.)
You can pass a System.Globalization.CultureInfo object that specifies the culture whose formatting is to be used. Its System.Globalization.CultureInfo.NumberFormat property provides formatting information.
You can pass a custom IFormatProvider implementation. Its IFormatProvider.GetFormat(Type) method must instantiate and return the System.Globalization.NumberFormatInfo object that provides formatting information.
If provider is null, the System.Globalization.NumberFormatInfo object for the current culture is used.