System.Number.TryParseInt32 C# (CSharp) Method

TryParseInt32() static private method

static private TryParseInt32 ( String s, NumberStyles style, NumberFormatInfo info, Int32 &result ) : Boolean
s String
style NumberStyles
info NumberFormatInfo
result Int32
return Boolean
        internal unsafe static Boolean TryParseInt32(String s, NumberStyles style, NumberFormatInfo info, out Int32 result) {

            Byte * numberBufferBytes = stackalloc Byte[NumberBuffer.NumberBufferBytes];
            NumberBuffer number = new NumberBuffer(numberBufferBytes);
            result = 0;
    
            if (!TryStringToNumber(s, style, ref number, info, false)) {
                return false;
            }

            if ((style & NumberStyles.AllowHexSpecifier) != 0) {
                if (!HexNumberToInt32(ref number, ref result)) { 
                    return false;
                }
            }
            else {
                if (!NumberToInt32(ref number, ref result)) {
                    return false;
                }
            }
            return true;           
        }

Usage Example

示例#1
0
        private static bool TryParse(string s, NumberStyles style, NumberFormatInfo info, out short result)
        {
            int num;

            result = 0;
            if (!Number.TryParseInt32(s, style, info, out num))
            {
                return(false);
            }
            if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
            {
                if ((num < 0) || (num > 0xffff))
                {
                    return(false);
                }
                result = (short)num;
                return(true);
            }
            if ((num < -32768) || (num > 0x7fff))
            {
                return(false);
            }
            result = (short)num;
            return(true);
        }
All Usage Examples Of System.Number::TryParseInt32