System.Int16.Parse Method

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

Syntax

public static short Parse (string s, IFormatProvider provider)

Parameters

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

Returns

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

Exceptions

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

Remarks

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

An 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 decimal digits, only leading and trailing spaces together with a leading sign are allowed in s. To explicitly define the style elements together with the culture-specific formatting information that can be present in s, use the short.Parse(string, System.Globalization.NumberStyles, IFormatProvider) method.

The provider parameter is an IFormatProvider implementation that obtains a System.Globalization.NumberFormatInfo object. The System.Globalization.NumberFormatInfo provides culture-specific information about the format of s. If provider is null, the System.Globalization.NumberFormatInfo for the current culture is used.

Requirements

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