示例#1
0
        // Parses an integer from a String in the given style.  If
        // a NumberFormatInfo isn't specified, the current culture's
        // NumberFormatInfo is assumed.
        //
        /// <include file='doc\Int32.uex' path='docs/doc[@for="Int32.Parse3"]/*' />
        public static int Parse(String s, NumberStyles style, IFormatProvider provider)
        {
            NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);

            NumberFormatInfo.ValidateParseStyle(style);
            return(Number.ParseInt32(s, style, info));
        }
示例#2
0
        public static ushort Parse(String s, NumberStyles style)
        {
            NumberFormatInfo.ValidateParseStyle(style);
            uint i = Number.ParseUInt32(s, style);

            if (i > MaxValue)
            {
                throw new OverflowException("Overflow_UInt16");
            }
            return((ushort)i);
        }
示例#3
0
        // Parses an unsigned byte from a String in the given style.  If
        // a NumberFormatInfo isn't specified, the current culture's
        // NumberFormatInfo is assumed.
        //| <include path='docs/doc[@for="Byte.Parse3"]/*' />
        public static byte Parse(String s, NumberStyles style)
        {
            NumberFormatInfo.ValidateParseStyle(style);
            int i = Number.ParseInt32(s, style);

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException("Overflow_Byte");
            }
            return((byte)i);
        }
示例#4
0
 public unsafe static UIntPtr Parse(String s, NumberStyles style)
 {
     NumberFormatInfo.ValidateParseStyle(style);
     if (sizeof(UIntPtr) == 4)
     {
         return(Number.ParseUInt32(s, style));
     }
     else
     {
         return(Number.ParseUInt64(s, style));
     }
 }
示例#5
0
        public static ushort Parse(String s, NumberStyles style, IFormatProvider provider)
        {
            NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);

            NumberFormatInfo.ValidateParseStyle(style);
            uint i = Number.ParseUInt32(s, style, info);

            if (i > MaxValue)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_UInt16"));
            }
            return((ushort)i);
        }
示例#6
0
        // Parses an unsigned byte from a String in the given style.  If
        // a NumberFormatInfo isn't specified, the current culture's
        // NumberFormatInfo is assumed.
        /// <include file='doc\Byte.uex' path='docs/doc[@for="Byte.Parse3"]/*' />
        public static byte Parse(String s, NumberStyles style, IFormatProvider provider)
        {
            NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);

            NumberFormatInfo.ValidateParseStyle(style);
            int i = Number.ParseInt32(s, style, info);

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_Byte"));
            }
            return((byte)i);
        }
示例#7
0
        public static sbyte Parse(String s, NumberStyles style)
        {
            NumberFormatInfo.ValidateParseStyle(style);
            int i = Number.ParseInt32(s, style);

            if (((style & NumberStyles.AllowHexSpecifier) != 0) && (i <= Byte.MaxValue)) // We are parsing a hexadecimal number
            {
                return((sbyte)i);
            }

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException("Overflow_SByte");
            }
            return((sbyte)i);
        }
示例#8
0
        public static sbyte Parse(String s, NumberStyles style, IFormatProvider provider)
        {
            NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);

            NumberFormatInfo.ValidateParseStyle(style);
            int i = Number.ParseInt32(s, style, info);

            if (((style & NumberStyles.AllowHexSpecifier) != 0) && (i <= Byte.MaxValue))             // We are parsing a hexadecimal number
            {
                return((sbyte)i);
            }

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException(Environment.GetResourceString("Overflow_SByte"));
            }
            return((sbyte)i);
        }
示例#9
0
        //| <include path='docs/doc[@for="Int16.Parse3"]/*' />
        public static short Parse(String s, NumberStyles style)
        {
            NumberFormatInfo.ValidateParseStyle(style);

            int i = Number.ParseInt32(s, style);

            // 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) && (i <= UInt16.MaxValue)) // We are parsing a hexadecimal number
            {
                return((short)i);
            }

            if (i < MinValue || i > MaxValue)
            {
                throw new OverflowException("Overflow_Int16");
            }
            return((short)i);
        }
示例#10
0
 /// <include file='doc\Int32.uex' path='docs/doc[@for="Int32.Parse1"]/*' />
 public static int Parse(String s, NumberStyles style)
 {
     NumberFormatInfo.ValidateParseStyle(style);
     return(Parse(s, style, null));
 }
示例#11
0
 public static uint Parse(String s, NumberStyles style)
 {
     NumberFormatInfo.ValidateParseStyle(style);
     return(Number.ParseUInt32(s, style));
 }
示例#12
0
 // Parses a long from a String in the given style.  If
 // a NumberFormatInfo isn't specified, the current culture's
 // NumberFormatInfo is assumed.
 //
 //| <include path='docs/doc[@for="Int64.Parse3"]/*' />
 public static long Parse(String s, NumberStyles style)
 {
     NumberFormatInfo.ValidateParseStyle(style);
     return(Number.ParseInt64(s, style));
 }