/// <summary> /// Attempts to produce a 128-bit integer from a string representation. /// </summary> /// <param name="text">A string containing the base-10 representation of a 128-bit integer value.</param> /// <param name="value">If the parse was successful, the 128-bit integer represented by <paramref name="text"/>.</param> /// <returns><see langword="true"/> if the parse was successful, otherwise <see langword="false"/>.</returns> public static bool TryParse(string text, out Int128 value) { ParseResult result = UInt128.TryParse(text, true, out UInt128 u); if (result == ParseResult.Success) { value = new Int128(u); return(true); } else { value = Int128.Zero; return(false); } }
/// <summary> /// Produces a 128-bit integer from its string representation. /// </summary> /// <param name="text">A string containing the base-10 representation of a 128-bit integer value.</param> /// <returns>The 128-bit integer represented by <paramref name="text"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="text"/> was <see langword="null"/>.</exception> /// <exception cref="FormatException"><paramref name="text"/> did not contain a valid representation of an integer.</exception> /// <exception cref="OverflowException"><paramref name="text"/> represented an integer outside the range of <see cref="Int128"/>.</exception> public static Int128 Parse(string text) { ParseResult result = UInt128.TryParse(text, true, out UInt128 u); if (result == ParseResult.Null) { throw new ArgumentNullException(nameof(text)); } if (result == ParseResult.Overflow) { throw new OverflowException(); } if (result != ParseResult.Success) { throw new FormatException(); } return(new Int128(u)); }