Microsoft has made the BCL available online at: http://referencesource.microsoft.com
Calling Convert.ToInt32(string)
will eventually call int.Parse
, which in turn will eventually call the actual routine on an internal Number
class here:
One of the basic routines listed there is as follows:
[System.Security.SecuritySafeCritical] // auto-generated
private unsafe static Boolean NumberToInt32(ref NumberBuffer number, ref Int32 value) {
Int32 i = number.scale;
if (i > Int32Precision || i < number.precision) {
return false;
}
char * p = number.digits;
Contract.Assert(p != null, "");
Int32 n = 0;
while (--i >= 0) {
if ((UInt32)n > (0x7FFFFFFF / 10)) {
return false;
}
n *= 10;
if (*p != '\0') {
n += (Int32)(*p++ - '0');
}
}
if (number.sign) {
n = -n;
if (n > 0) {
return false;
}
}
else {
if (n < 0) {
return false;
}
}
value = n;
return true;
}