BigInteger::Parse Method (String^, IFormatProvider^)
Converts the string representation of a number in a specified culture-specific format to its BigInteger equivalent.
Assembly: System.Numerics (in System.Numerics.dll)
A string that contains a number to convert.
An object that provides culture-specific formatting information about value.
Return ValueType: System.Numerics::BigInteger
A value that is equivalent to the number specified in the value parameter.
The value parameter should be the string representation of a number in the following form:
Elements in square brackets ([ and ]) are optional. The following table describes each element.
Optional white space.
An optional sign. Valid sign characters are determined by the NumberFormatInfo::NegativeSign and NumberFormatInfo::PositiveSign properties of the NumberFormatInfo object that is returned by the provider object's GetFormat method.
A sequence of digits ranging from 0 to 9. Any leading zeros are ignored.
The string specified by the value parameter is interpreted using the NumberStyles::Integer style. It cannot contain any group separators or decimal separator, and it cannot have a decimal portion.
If you use the Parse method to round-trip the string representation of a BigInteger value that was output by the ToString method, you should use the BigInteger::ToString(String^) method with the "R" format specifier to generate the string representation of the BigInteger value. Otherwise, the string representation of the BigInteger preserves only the 50 most significant digits of the original value, and data may be lost when you use the Parse method to restore the BigInteger value.
The provider parameter is an IFormatProvider implementation whose GetFormat method returns a NumberFormatInfo object that provides culture-specific formatting information. When the method is invoked, it calls the provider parameter's GetFormat method and passes it a Type object that represents the NumberFormatInfo type. The GetFormat method then returns the NumberFormatInfo object that provides information about the format of the value parameter. There are three ways to use the provider parameter to supply custom formatting information to the parse operation:
You can pass a CultureInfo object that represents the culture that supplies formatting information. Its GetFormat method returns the NumberFormatInfo object that provides numeric formatting information for that culture.
If provider is null, the formatting of value is interpreted based on the NumberFormatInfo object of the current culture.
The following examples show two ways to define the tilde (~) as a negative sign for formatting BigInteger values. Note that to display the BigInteger values in the same format as the original strings, your code must call the BigInteger::ToString(IFormatProvider^) method and pass it the NumberFormatInfo object that provides formatting information.
A BigInteger object can then be instantiated with the following code:
The second example is more straightforward. It passes the NumberFormatInfo object that provides formatting information to the provider parameter.
Available since 8
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Available since 8.1