System.Number.ParseInt32 C# (CSharp) Method

ParseInt32() static private method

static private ParseInt32 ( String s, NumberStyles style, NumberFormatInfo info ) : Int32
s String
style NumberStyles
info NumberFormatInfo
return Int32
        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;           
        }

Usage Example

示例#1
0
        private static short Parse(String s, NumberStyles style, NumberFormatInfo info)
        {
            int i = 0;

            try {
                i = Number.ParseInt32(s, style, info);
            }
            catch (OverflowException e) {
                throw new OverflowException(Environment.GetResourceString("Overflow_Int16"), e);
            }

            // We need this check here since we don't allow signs to specified in hex numbers. So we fixup the result
            // for negative numbers
            if ((style & NumberStyles.AllowHexSpecifier) != 0)   // We are parsing a hexadecimal number
            {
                if ((i < 0) || (i > UInt16.MaxValue))
                {
                    throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
                }
                return((short)i);
            }

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
            }
            return((short)i);
        }
All Usage Examples Of System.Number::ParseInt32