> public static int Parse(String s) { > return Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo); > } >>
> internal unsafe static Int32 ParseInt32(String s, NumberStyles style, NumberFormatInfo info) { > > Byte * numberBufferBytes = stackalloc Byte[NumberBuffer.NumberBufferBytes]; > NumberBuffer number = new NumberBuffer(numberBufferBytes); > Int32 i = 0; > > StringToNumber(s, style, ref number, info, false); > > if ((style & NumberStyles.AllowHexSpecifier) != 0) { > if (!HexNumberToInt32(ref number, ref i)) { > throw new OverflowException(Environment.GetResourceString("Overflow_Int32")); > } > } > else { > if (!NumberToInt32(ref number, ref i)) { > throw new OverflowException(Environment.GetResourceString("Overflow_Int32")); > } > } > return i; > } >>Number.StringToNumber
> private unsafe static void StringToNumber(String str, NumberStyles options, ref NumberBuffer number, NumberFormatInfo info, Boolean parseDecimal) { > > if (str == null) { > throw new ArgumentNullException("String"); > } > Contract.EndContractBlock(); > Contract.Assert(info != null, ""); > fixed (char* stringPointer = str) { > char * p = stringPointer; > if (!ParseNumber(ref p, options, ref number, null, info , parseDecimal) > || (p - stringPointer < str.Length && !TrailingZeros(str, (int)(p - stringPointer)))) { > throw new FormatException(Environment.GetResourceString("Format_InvalidString")); > } > } > } >>
> public static bool TryParse(String s, out Int32 result) { > return Number.TryParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result); > } >>
> internal unsafe static Boolean TryParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt, out Double result) { > Byte * numberBufferBytes = stackalloc Byte[NumberBuffer.NumberBufferBytes]; > NumberBuffer number = new NumberBuffer(numberBufferBytes); > result = 0; > > > if (!TryStringToNumber(value, options, ref number, numfmt, false)) { > return false; > } > if (!NumberBufferToDouble(number.PackForNative(), ref result)) { > return false; > } > return true; > } >>
> internal unsafe static Boolean TryStringToNumber(String str, NumberStyles options, ref NumberBuffer number, StringBuilder sb, NumberFormatInfo numfmt, Boolean parseDecimal) { > > if (str == null) { > return false; > } > Contract.Assert(numfmt != null, ""); > > fixed (char* stringPointer = str) { > char * p = stringPointer; > if (!ParseNumber(ref p, options, ref number, sb, numfmt, parseDecimal) > || (p - stringPointer < str.Length && !TrailingZeros(str, (int)(p - stringPointer)))) { > return false; > } > } > > return true; > } >Interesting - so Parse() throws exceptions all the way back up the chain - two in StringToNumber and two more in Int32 ParseInt32 ; TryParse() has none.