BigInteger::TryParse Method (String, BigInteger%)
Tries to convert the string representation of a number to its BigInteger equivalent, and returns a value that indicates whether the conversion succeeded.
Assembly: System.Numerics (in System.Numerics.dll)
Parameters
- value
- Type: System::String
The string representation of a number.
- result
- Type: System.Numerics::BigInteger%
When this method returns, contains the BigInteger equivalent to the number that is contained in value, or zero (0) if the conversion fails. The conversion fails if the value parameter is nullptr or is not of the correct format. This parameter is passed uninitialized.
| Exception | Condition |
|---|---|
| ArgumentNullException | value is nullptr. |
The TryParse(String, BigInteger%) method is like the Parse(String) method, except that it does not throw an exception if the conversion fails. This method eliminates the need to use exception handling to test for a FormatException if value is invalid and cannot be successfully parsed.
The value parameter should be the string representation of a decimal number in the following form:
[ws][sign]digits[ws]
Elements in square brackets ([ and ]) are optional. The following table describes each element.
Element | Description |
|---|---|
ws | Optional white space. |
sign | An optional sign. Valid sign characters are determined by the NumberFormatInfo::NegativeSign and NumberFormatInfo::PositiveSign properties of the current culture. |
digits | A sequence of decimal digits ranging from 0 to 9. |
Note |
|---|
The string specified by the value parameter cannot contain any group separators or decimal separator, and it cannot have a decimal portion. |
The value parameter is interpreted by using the NumberStyles::Integer style. In addition to the 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 value, call the TryParse(String, NumberStyles, IFormatProvider, BigInteger%) method.
The value parameter is parsed by using the formatting information in a NumberFormatInfo object for the current culture. For more information, see NumberFormatInfo::CurrentInfo.
This overload interprets all digits in the value parameter as decimal digits. To parse the string representation of a hexadecimal number, call the TryParse(String, NumberStyles, IFormatProvider, BigInteger%) overload instead.
The following example uses the TryParse(String, BigInteger%) method to instantiate two BigInteger objects. If the conversions succeed, it multiplies each object by another number and then calls the Compare method to determine the relationship between the two objects.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note