System.Byte.Parse Method

Converts the string representation of a number in a specified culture-specific format to its byte equivalent.

Syntax

public static byte Parse (string s, IFormatProvider provider)

Parameters

s
A string that contains a number to convert. The string is interpreted using the System.Globalization.NumberStyles.Integer style.
provider
An object that supplies culture-specific parsing information about s. If provider is null, the thread current culture is used.
s
A string that contains a number to convert. The string is interpreted using the System.Globalization.NumberStyles.Integer style.
provider
An object that supplies culture-specific parsing information about s. If provider is null, the thread current culture is used.

Returns

A byte value that is equivalent to the number contained in s.

Exceptions

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

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

Optional white space.

sign

An optional positive 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 together with a leading sign are allowed. (If the sign is present, it must be a positive sign or the method throws an OverflowException.) To explicitly define the style elements together with the culture-specific formatting information that can be present in s, use the byte.Parse(string, System.Globalization.NumberStyles, IFormatProvider) method.

The s parameter is parsed using the formatting information in a System.Globalization.NumberFormatInfo object supplied by provider. 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 used in parsing. If provider is null, the thread 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